Skip to content

Commit

Permalink
SDSS-1379: Set default value for Featured field (#504)
Browse files Browse the repository at this point in the history
* SDSS-1379: Set default value for Featured field.
  • Loading branch information
joegl authored Oct 11, 2024
1 parent 463cd60 commit 74cd07a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ label: Featured
description: 'Feature this content in lists and feeds.'
required: false
translatable: false
default_value: { }
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: Featured
Expand Down
31 changes: 31 additions & 0 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,34 @@ function sdss_profile_update_10016(&$sandbox) {

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

/**
* Set the Featured field to FALSE on existing Event nodes without a set value.
*/
function sdss_profile_update_10017(&$sandbox) {
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
if (!isset($sandbox['count'])) {
$nids = $node_storage->getQuery()
->accessCheck(FALSE)
->condition('type', 'stanford_event')
->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_featured')) {
continue;
}
if ($node->get('su_sdss_featured')->isEmpty()) {
$node->set('su_sdss_featured', FALSE)->save();
}
}

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

0 comments on commit 74cd07a

Please sign in to comment.