From c2303a111fa3a5b33e47ec9cc246d26d49b206b5 Mon Sep 17 00:00:00 2001 From: Joe Gilliland-Lloyd <6943710+joegl@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:38:44 -0500 Subject: [PATCH] SDSS-1337: Track imported News Sharing content (#478) * SDSS-1337: Track imported News Sharing content. --- ...orm_display.node.stanford_news.default.yml | 12 ++-- ...iew_display.node.stanford_news.default.yml | 2 + ...lay.node.stanford_news.search_indexing.yml | 2 + ...splay.node.stanford_news.stanford_card.yml | 2 + ...view_display.node.stanford_news.teaser.yml | 2 + ...ord_news.su_sdss_imported_news_sharing.yml | 21 ++++++ ...age.node.su_sdss_imported_news_sharing.yml | 18 +++++ ...grate_plus.migration.sdss_news_sharing.yml | 2 + .../sync/views.view.sdss_news_sharing.yml | 38 +++++++++++ .../sdss/sdss_profile/sdss_profile.install | 68 ++++++++++++++++++- 10 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_news.su_sdss_imported_news_sharing.yml create mode 100644 docroot/profiles/sdss/sdss_profile/config/sync/field.storage.node.su_sdss_imported_news_sharing.yml diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_form_display.node.stanford_news.default.yml b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_form_display.node.stanford_news.default.yml index d8cbf3e5d..6b33db078 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_form_display.node.stanford_news.default.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_form_display.node.stanford_news.default.yml @@ -5,6 +5,7 @@ dependencies: config: - field.field.node.stanford_news.layout_builder__layout - field.field.node.stanford_news.stanford_intranet__access + - field.field.node.stanford_news.su_sdss_imported_news_sharing - field.field.node.stanford_news.su_metatags - field.field.node.stanford_news.su_news_banner - field.field.node.stanford_news.su_news_banner_media_caption @@ -189,7 +190,9 @@ content: weight: 4 region: content settings: + view_mode: default preview_view_mode: default + form_display_mode: default nesting_depth: 0 require_layouts: 1 empty_message: '' @@ -247,14 +250,6 @@ content: collapsed: false revision: false removed_reference: keep - auto_open: true - allow_edit: true - hide_fieldset: false - hide_title: false - config_labels_button: _none - labels: { } - add_existing_widget: autocomplete - auto_open_edit_form: false third_party_settings: change_labels: add_another: 'Add another Media Contact' @@ -390,6 +385,7 @@ hidden: sticky: true su_news_dek: true su_sdss_import_source: true + su_sdss_imported_news_sharing: true uid: true unpublish_on: true url_redirects: true diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.default.yml b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.default.yml index 5d6f42b77..63b167073 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.default.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.default.yml @@ -6,6 +6,7 @@ dependencies: - core.base_field_override.node.stanford_news.title - field.field.node.stanford_news.layout_builder__layout - field.field.node.stanford_news.stanford_intranet__access + - field.field.node.stanford_news.su_sdss_imported_news_sharing - field.field.node.stanford_news.su_metatags - field.field.node.stanford_news.su_news_banner - field.field.node.stanford_news.su_news_banner_media_caption @@ -625,4 +626,5 @@ hidden: stanford_intranet__access: true su_metatags: true su_news_source: true + su_sdss_imported_news_sharing: true su_shared_tags: true diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.search_indexing.yml b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.search_indexing.yml index 45ac659d4..104c27a1c 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.search_indexing.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.search_indexing.yml @@ -6,6 +6,7 @@ dependencies: - core.entity_view_mode.node.search_indexing - field.field.node.stanford_news.layout_builder__layout - field.field.node.stanford_news.stanford_intranet__access + - field.field.node.stanford_news.su_sdss_imported_news_sharing - field.field.node.stanford_news.su_metatags - field.field.node.stanford_news.su_news_banner - field.field.node.stanford_news.su_news_banner_media_caption @@ -136,6 +137,7 @@ hidden: su_metatags: true su_news_dek: true su_sdss_import_source: true + su_sdss_imported_news_sharing: true su_sdss_media_contacts: true su_sdss_media_mention: true su_sdss_news_banner_caption: true diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.stanford_card.yml b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.stanford_card.yml index f1f155574..c1f4cdcac 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.stanford_card.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.stanford_card.yml @@ -6,6 +6,7 @@ dependencies: - core.entity_view_mode.node.stanford_card - field.field.node.stanford_news.layout_builder__layout - field.field.node.stanford_news.stanford_intranet__access + - field.field.node.stanford_news.su_sdss_imported_news_sharing - field.field.node.stanford_news.su_metatags - field.field.node.stanford_news.su_news_banner - field.field.node.stanford_news.su_news_banner_media_caption @@ -183,6 +184,7 @@ hidden: su_news_components: true su_news_dek: true su_sdss_import_source: true + su_sdss_imported_news_sharing: true su_sdss_media_contacts: true su_sdss_media_mention: true su_sdss_news_banner_caption: true diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.teaser.yml b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.teaser.yml index 9cb6c98e6..2cb5322ac 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.teaser.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/core.entity_view_display.node.stanford_news.teaser.yml @@ -6,6 +6,7 @@ dependencies: - core.entity_view_mode.node.teaser - field.field.node.stanford_news.layout_builder__layout - field.field.node.stanford_news.stanford_intranet__access + - field.field.node.stanford_news.su_sdss_imported_news_sharing - field.field.node.stanford_news.su_metatags - field.field.node.stanford_news.su_news_banner - field.field.node.stanford_news.su_news_banner_media_caption @@ -222,6 +223,7 @@ hidden: su_news_source: true su_news_topics: true su_sdss_import_source: true + su_sdss_imported_news_sharing: true su_sdss_media_contacts: true su_sdss_media_mention: true su_sdss_news_banner_caption: true diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_news.su_sdss_imported_news_sharing.yml b/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_news.su_sdss_imported_news_sharing.yml new file mode 100644 index 000000000..e8c2297ed --- /dev/null +++ b/docroot/profiles/sdss/sdss_profile/config/sync/field.field.node.stanford_news.su_sdss_imported_news_sharing.yml @@ -0,0 +1,21 @@ +uuid: bec5aa1e-8cb5-4e3f-9673-3198d96ca964 +langcode: en +status: true +dependencies: + config: + - field.storage.node.su_sdss_imported_news_sharing + - node.type.stanford_news +id: node.stanford_news.su_sdss_imported_news_sharing +field_name: su_sdss_imported_news_sharing +entity_type: node +bundle: stanford_news +label: 'Imported via News Sharing' +description: 'This content was imported from another site through News Sharing.' +required: false +translatable: true +default_value: { } +default_value_callback: '' +settings: + on_label: 'Yes' + off_label: 'No' +field_type: boolean diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/field.storage.node.su_sdss_imported_news_sharing.yml b/docroot/profiles/sdss/sdss_profile/config/sync/field.storage.node.su_sdss_imported_news_sharing.yml new file mode 100644 index 000000000..6486c5161 --- /dev/null +++ b/docroot/profiles/sdss/sdss_profile/config/sync/field.storage.node.su_sdss_imported_news_sharing.yml @@ -0,0 +1,18 @@ +uuid: 9e91a7b2-54be-4154-b251-b49040727100 +langcode: en +status: true +dependencies: + module: + - node +id: node.su_sdss_imported_news_sharing +field_name: su_sdss_imported_news_sharing +entity_type: node +type: boolean +settings: { } +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/migrate_plus.migration.sdss_news_sharing.yml b/docroot/profiles/sdss/sdss_profile/config/sync/migrate_plus.migration.sdss_news_sharing.yml index 84708e730..9c47b8689 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/migrate_plus.migration.sdss_news_sharing.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/migrate_plus.migration.sdss_news_sharing.yml @@ -63,8 +63,10 @@ source: stanford_minimal_html: stanford_minimal_html type: stanford_news image_path: 'public://media/sdss_news_sharing/' + imported_via_news_sharing: 1 process: type: constants/type + su_sdss_imported_news_sharing: constants/imported_via_news_sharing title: title image_file: - diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/views.view.sdss_news_sharing.yml b/docroot/profiles/sdss/sdss_profile/config/sync/views.view.sdss_news_sharing.yml index 83d352b8a..7535c9037 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/views.view.sdss_news_sharing.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/views.view.sdss_news_sharing.yml @@ -615,6 +615,44 @@ display: plugin_id: bundle value: stanford_news: stanford_news + su_sdss_imported_news_sharing_value: + id: su_sdss_imported_news_sharing_value + table: node__su_sdss_imported_news_sharing + field: su_sdss_imported_news_sharing_value + relationship: none + group_type: group + admin_label: '' + plugin_id: boolean + operator: '!=' + value: '1' + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + operator_limit_selection: false + operator_list: { } + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } style: type: serializer row: diff --git a/docroot/profiles/sdss/sdss_profile/sdss_profile.install b/docroot/profiles/sdss/sdss_profile/sdss_profile.install index cc9d7e773..95251fcf8 100644 --- a/docroot/profiles/sdss/sdss_profile/sdss_profile.install +++ b/docroot/profiles/sdss/sdss_profile/sdss_profile.install @@ -7,7 +7,6 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Menu\MenuTreeParameters; -use Drupal\Core\Site\Settings; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\node\NodeInterface; @@ -755,8 +754,7 @@ function _sdss_profile_reset_node_changed_time(NodeInterface $node, int $changed /** * Create su_sdss_media_mention field from configuration. */ -function sdss_profile_update_10001() -{ +function sdss_profile_update_10001() { $config_directory = \Drupal::service('config.storage.sync'); $field_storage = $config_directory->read('field.storage.node.su_sdss_media_mention'); $field_config = $config_directory->read('field.field.node.stanford_news.su_sdss_media_mention'); @@ -898,3 +896,67 @@ function sdss_profile_update_10007(&$sandbox) { $sandbox['#finished'] = empty($sandbox['pids']) ? 1 : ($sandbox['count'] - count($sandbox['pids'])) / $sandbox['count']; } + +/** + * Add imported via news sharing field to News. + */ +function sdss_profile_update_10008() { + $entity_type_manager = \Drupal::entityTypeManager(); + + $field_storage = $entity_type_manager->getStorage('field_storage_config'); + if (!$field_storage->load('node.su_sdss_imported_news_sharing')) { + $field_storage->create([ + 'uuid' => '9e91a7b2-54be-4154-b251-b49040727100', + 'field_name' => 'su_sdss_imported_news_sharing', + 'type' => 'boolean', + 'entity_type' => 'node', + 'cardinality' => 1, + ])->save(); + + $field_config_storage = $entity_type_manager->getStorage('field_config'); + $field_config_storage->create([ + 'entity_type' => 'node', + 'field_name' => 'su_sdss_imported_news_sharing', + 'bundle' => 'stanford_news', + 'label' => 'Imported via News Sharing', + 'description' => 'This content was imported from another site through News Sharing.', + ])->save(); + } +} + +/** + * Flag existing content imported via News Sharing. + */ +function sdss_profile_update_10009(&$sandbox) { + if (!isset($sandbox['count'])) { + $db = \Drupal::database(); + if ($db->schema()->tableExists('migrate_map_sdss_news_sharing')) { + $ids = array_keys($db->select('migrate_map_sdss_news_sharing', 'm') + ->fields('m', ['destid1']) + ->execute() + ->fetchAllAssoc('destid1')); + $sandbox['nids'] = $ids; + $sandbox['count'] = count($sandbox['nids']); + } else { + $sandbox['#finished'] = 1; + return; + } + } + + $node_ids = array_splice($sandbox['nids'], 0, 250); + + if (empty($node_ids)) { + $sandbox['#finished'] = 1; + return; + } + + $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($node_ids); + foreach ($nodes as $node) { + if (!$node->hasField('su_sdss_imported_news_sharing')) { + continue; + } + $node->set('su_sdss_imported_news_sharing', TRUE)->save(); + } + + $sandbox['#finished'] = empty($sandbox['nids']) ? 1 : ($sandbox['count'] - count($sandbox['nids'])) / $sandbox['count']; +}