Skip to content

Commit

Permalink
SDSS-1360: DEV | Set Featured Events default value for existing conte…
Browse files Browse the repository at this point in the history
…nt (#482)

* SDSS-1360: DEV | Set Featured Events default value for existing content.
  • Loading branch information
joegl authored Sep 3, 2024
1 parent f9ef95d commit 1dce19d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,49 @@ function sdss_profile_update_10009(&$sandbox) {

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

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

// Create su_sdss_featured 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 the Featured field to FALSE on all existing Event Nodes.
*/
function sdss_profile_update_10011(&$sandbox) {
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
if (!isset($sandbox['count'])) {
$nids = $node_storage->getQuery()
->accessCheck(FALSE)
->condition('type', 'stanford_event')
->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);
foreach ($nodes as $node) {
if (!$node->hasField('su_sdss_featured')) {
continue;
}
$node->set('su_sdss_featured', FALSE)->save();
}

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

0 comments on commit 1dce19d

Please sign in to comment.