Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDSS-1378: FIX | Set default value for explore more picker #502

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
}
Loading