diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_event.su_sdss_featured.yml b/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_event.su_sdss_featured.yml index 0df605019..177cfe9bc 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_event.su_sdss_featured.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_event.su_sdss_featured.yml @@ -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 diff --git a/docroot/profiles/sdss/sdss_profile/sdss_profile.install b/docroot/profiles/sdss/sdss_profile/sdss_profile.install index 1f5cf8281..abe7bc2d2 100644 --- a/docroot/profiles/sdss/sdss_profile/sdss_profile.install +++ b/docroot/profiles/sdss/sdss_profile/sdss_profile.install @@ -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']; +}