Skip to content

Commit

Permalink
SDSS-1337: Track imported News Sharing content (#478)
Browse files Browse the repository at this point in the history
* SDSS-1337: Track imported News Sharing content.
  • Loading branch information
joegl authored Aug 22, 2024
1 parent 70f3e23 commit c2303a1
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ''
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
68 changes: 65 additions & 3 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'];
}

0 comments on commit c2303a1

Please sign in to comment.