Skip to content

Commit

Permalink
SDSS-1359: Set Explore More Options default for existing content (#483)
Browse files Browse the repository at this point in the history
* SDSS-1359: Set Explore More Options default for existing content.
  • Loading branch information
joegl authored Sep 3, 2024
1 parent 1dce19d commit 61139bf
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,58 @@ function sdss_profile_update_10011(&$sandbox) {

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

/**
* Create su_sdss_explore_more_picker field from configuration.
*/
function sdss_profile_update_10012() {
$config_directory = \Drupal::service('config.storage.sync');
$field_storage = $config_directory->read('field.storage.node.su_sdss_explore_more_picker');
$field_config = $config_directory->read('field.field.node.stanford_news.su_sdss_explore_more_picker');

// Create su_sdss_explore_more_picker field from exported configuration.
if (!FieldStorageConfig::loadByName($field_storage['entity_type'], $field_storage['field_name'])) {
FieldStorageConfig::create($field_storage)->save();
}
if (!FieldConfig::loadByName($field_config['entity_type'], $field_config['bundle'], $field_config['field_name'])) {
FieldConfig::create($field_config)->save();
}
}

/**
* Set default value for the su_sdss_explore_more_picker field on all existing
* nodes.
*/
function sdss_profile_update_10013() {
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
if (!isset($sandbox['count'])) {
$nids = $node_storage->getQuery()
->accessCheck(FALSE)
->condition('type', 'stanford_news')
->sort('created')
->execute();
$sandbox['nids'] = $nids;
$sandbox['count'] = count($sandbox['nids']);
}

$node_ids = array_splice($sandbox['nids'], 0, 250);
/** @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;
}
$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 61139bf

Please sign in to comment.