Skip to content

Commit

Permalink
SDSS-1378: FIX | Set default value for explore more picker (#502)
Browse files Browse the repository at this point in the history
* SDSS-1378: FIX | Set default value for explore more picker.
  • Loading branch information
joegl authored Oct 11, 2024
1 parent a208304 commit 0f5938b
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ function sdss_profile_update_10012() {
* Set default value for the su_sdss_explore_more_picker field on all existing
* nodes.
*/
function sdss_profile_update_10013() {
function sdss_profile_update_10013(&$sandbox) {
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
if (!isset($sandbox['count'])) {
Expand Down Expand Up @@ -1106,3 +1106,43 @@ function sdss_profile_update_10015(&$sandbox) {

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

/**
* Set default value for the su_sdss_explore_more_picker field on all existing
* nodes without a set value.
*/
function sdss_profile_update_10016(&$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);
$default_value = [
0 => [
'target_id' => 'explore_more_news',
'display_id' => 'explore_more_random',
'arguments' => '',
'items_to_display' => '',
]
];
foreach ($nodes as $node) {
if (!$node->hasField('su_sdss_explore_more_picker')) {
continue;
}
if ($node->get('su_sdss_explore_more_picker')->isEmpty()) {
$node->set('su_sdss_explore_more_picker', $default_value)->save();
}
}

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

0 comments on commit 0f5938b

Please sign in to comment.