Skip to content

Commit

Permalink
SDSS-1377: Set default value for Imported via News Sharing field (#501)
Browse files Browse the repository at this point in the history
* SDSS-1377: Set default value for Imported via News Sharing field.
  • Loading branch information
joegl authored Oct 11, 2024
1 parent 856701d commit a208304
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ label: 'Imported via News Sharing'
description: 'This content was imported from another site through News Sharing.'
required: false
translatable: true
default_value: { }
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: 'Yes'
Expand Down
32 changes: 32 additions & 0 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,35 @@ function sdss_profile_update_10014() {
// Theme was already uninstalled.
}
}

/**
* Set the Imported via News Sharing field to FALSE on existing News nodes
* without a set value.
*/
function sdss_profile_update_10015(&$sandbox) {
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
if (!isset($sandbox['count'])) {
$nids = $node_storage->getQuery()
->accessCheck(FALSE)
->condition('type', 'stanford_news')
->sort('created', 'DESC')
->execute();
$sandbox['nids'] = $nids;
$sandbox['count'] = count($sandbox['nids']);
}

$node_ids = array_splice($sandbox['nids'], 0, 100);
/** @var \Drupal\node\NodeInterface[] $nodes */
$nodes = $node_storage->loadMultiple($node_ids);
foreach ($nodes as $node) {
if (!$node->hasField('su_sdss_imported_news_sharing')) {
continue;
}
if ($node->get('su_sdss_imported_news_sharing')->isEmpty()) {
$node->set('su_sdss_imported_news_sharing', FALSE)->save();
}
}

$sandbox['#finished'] = empty($sandbox['nids']) ? 1 : ($sandbox['count'] - count($sandbox['nids'])) / $sandbox['count'];
}

0 comments on commit a208304

Please sign in to comment.