diff --git a/modules/tide_news/tide_news.post_update.php b/modules/tide_news/tide_news.post_update.php deleted file mode 100644 index 0b71ef9b..00000000 --- a/modules/tide_news/tide_news.post_update.php +++ /dev/null @@ -1,125 +0,0 @@ -loadInclude('tide_core', 'inc', 'includes/helpers'); - $config_location = [\Drupal::service('extension.list.module')->getPath('tide_news') . '/config/install']; - $config_read = _tide_read_config('field.field.node.news.field_show_feature_image', $config_location, TRUE); - $storage = \Drupal::entityTypeManager()->getStorage('field_config'); - $id = $storage->getIDFromConfigName('field.field.node.news.field_show_feature_image', $storage->getEntityType()->getConfigPrefix()); - if ($storage->load($id) === NULL) { - $config_entity = $storage->createFromStorageRecord($config_read); - $config_entity->save(); - } - - $config = FieldConfig::load('node.news.field_featured_image'); - $config->setDescription( - '

The feature image displays by default below the date on published news pages. You have the option to turn off the feature image. The feature image displays in promotion or navigation cards linking to this page when Card display style is set as Thumbnail or Profile. JPEG is the preferred format.

See the SDP guide on image ratios, sizes and component use.

', - ); - $config->save(); - $field_show_feature_image = [ - 'type' => 'boolean_checkbox', - 'weight' => 100, - 'region' => 'content', - 'settings' => [ - 'display_label' => TRUE, - ], - 'third_party_settings' => [], - ]; - $group_feature_image = [ - 'children' => [ - 'field_featured_image', - 'field_show_feature_image', - ], - 'label' => 'Feature image', - 'region' => 'content', - 'parent_name' => '', - 'weight' => 2, - 'format_type' => 'tab', - 'format_settings' => [ - 'classes' => '', - 'show_empty_fields' => FALSE, - 'id' => '', - 'label_as_html' => FALSE, - 'formatter' => 'closed', - 'description' => '', - 'required_fields' => TRUE, - ], - ]; - - /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */ - $entity_form_display = Drupal::entityTypeManager()->getStorage('entity_form_display')->load('node.news.default'); - $field_group = $entity_form_display->getThirdPartySettings('field_group'); - if (is_array($field_group) && isset($field_group['group_section_content'])) { - $field_group['group_feature_image'] = $group_feature_image; - $field_featured_image_settings = $entity_form_display->getComponent('field_featured_image'); - $field_featured_image_settings['settings']['open'] = TRUE; - $field_group['group_feature_image']['weight'] = $field_featured_image_settings['weight']; - $field_featured_image_settings['weight'] = 99; - $entity_form_display->setThirdPartySetting('field_group', 'group_feature_image', $field_group['group_feature_image']); - $entity_form_display->setComponent('field_featured_image', $field_featured_image_settings); - $entity_form_display->setComponent('field_show_feature_image', $field_show_feature_image); - $entity_form_display->save(); - } - - $index = Index::load('node'); - $field = new Field($index, 'field_show_feature_image'); - $field->setType('boolean'); - $field->setDatasourceId('entity:node'); - $field->setPropertyPath('field_show_feature_image'); - $field->setLabel('Display the feature image in the body of your news page'); - $index->addField($field); - $index->save(); -} - -/** - * Update field_show_feature_image field. - */ -function tide_news_post_update_002_update_field_show_feature_image(&$sandbox) { - if (!isset($sandbox['total'])) { - $count = \Drupal::entityTypeManager() - ->getStorage('node') - ->getQuery() - ->accessCheck(FALSE) - ->condition('type', 'news') - ->count() - ->execute(); - $sandbox['total'] = $count; - $sandbox['current'] = 0; - $sandbox['processed'] = 0; - $sandbox['#finished'] = $count ? 0 : 1; - } - $batch_size = 50; - $node_ids = \Drupal::entityTypeManager() - ->getStorage('node') - ->getQuery() - ->accessCheck(FALSE) - ->condition('nid', $sandbox['current'], '>') - ->condition('type', 'news') - ->sort('nid', 'ASC') - ->range(0, $batch_size) - ->execute(); - foreach ($node_ids as $node_id) { - $sandbox['current'] = $node_id; - $node = Node::load($node_id); - if ($node instanceof Node && $node->hasField('field_show_feature_image') && is_string($node->uuid())) { - $node->set('field_show_feature_image', TRUE); - $node->save(); - } - $sandbox['processed']++; - } - $sandbox['#finished'] = $sandbox['total'] ? $sandbox['processed'] / $sandbox['total'] : 1; - $sandbox['#finished'] = $sandbox['#finished'] > 1 ? 1 : $sandbox['#finished']; -}