Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wri 489 social links #356

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ff614e
WRI 489: add social media vocab, field, display
komejo Feb 1, 2025
e9c6143
WRI-489: add Social Media Sites paragraph
komejo Feb 11, 2025
7ea6a84
WRI-489: person, program, project, and pub configs
komejo Feb 15, 2025
ccd2883
WRI-489: field, form display, view modes
komejo Feb 18, 2025
aebc553
WRI-489: add explicit form display content import
komejo Feb 18, 2025
9347bb1
WRI-489: populate the Social Media vocabulary
komejo Feb 18, 2025
4dcef5c
WRI-489: post-update hook to migrate from twitter
komejo Feb 18, 2025
ea2ac79
WRI-489: update display modes
komejo Feb 18, 2025
f42da39
WRI-489: paragraph & taxonomy display modes, SASS
komejo Feb 19, 2025
227a0bb
WRI-489: theming, layouts, display mode updats
komejo Feb 20, 2025
240ab94
WRI-489: Layout Builder defaults
komejo Feb 21, 2025
195e149
WRI-489: Field and block overrides, theming
komejo Feb 24, 2025
b5e8a8c
DCS
komejo Feb 24, 2025
6d2da81
WRI-489: pull module dependency
komejo Feb 24, 2025
5357a2f
WRI-489: more dependency tweaks
komejo Feb 24, 2025
2d4759f
WRI-489: get the view_display working
komejo Feb 24, 2025
17d2c6f
Issue #489 fixing install config problems.
thinkshout-ci-bot Feb 25, 2025
e0283c0
WRI-489: PR feedback
komejo Feb 26, 2025
5b7d629
WRI-489: hide on subpage
komejo Feb 26, 2025
2fbce3a
WRI-489: publications do not need social media
komejo Feb 26, 2025
748b592
Issue #489 adding some help text about the handle.
thinkshout-ci-bot Feb 26, 2025
ecd30cf
I think we also need to add the main_content region or the paragraphs…
thinkshout-ci-bot Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
module:
- entity_reference_revisions
- node
- paragraphs
id: node.field_paragraphs
field_name: field_paragraphs
entity_type: node
type: entity_reference_revisions
settings:
target_type: paragraph
module: entity_reference_revisions
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
124 changes: 124 additions & 0 deletions modules/wri_node/wri_node.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Wri Node module code.
*/

use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;

/**
* Add the node settings values.
*/
Expand Down Expand Up @@ -146,3 +149,124 @@ function wri_node_update_10002() {
$field->save();
}
}

/**
* Implements hook_update_dependencies().
*/
function wri_node_update_dependencies() {
$dependencies['wri_node'][10401] = [
'wri_paragraph' => 10401,
];
$dependencies['wri_node'][10402] = [
'wri_person' => 10402,
'wri_program' => 10402,
'wri_project' => 10402,
];
return $dependencies;
}

/**
* Add field_paragraphs.
*/
function wri_node_update_10401() {
\Drupal::service('distro_helper.updates')->installConfig('field.storage.node.field_paragraphs', 'wri_node');

$message = 'Add field Paragraphs.';
return $message;
}

/**
* Migrate field_twitter_account values into a social_media_sites paragraph.
*/
function wri_node_update_10402() {
// Define the content types to process.
$content_types = ['program_center', 'microsite', 'person', 'project_detail'];

// Query for nodes with a non-empty field_twitter_account.
$query = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('type', $content_types, 'IN')
->exists('field_twitter_account');
$nids = $query->execute();

// Load the taxonomy term for Twitter from the Social Media sites vocabulary.
$twitter_terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties([
'vid' => 'social_media_sites',
'name' => 'Twitter',
]);
$twitter_term = $twitter_terms ? reset($twitter_terms) : NULL;

$nodes = Node::loadMultiple($nids);
$migrated_nids = [];

foreach ($nodes as $node) {
if ($node->hasField('field_twitter_account') && !$node->get('field_twitter_account')->isEmpty()) {
// Check if the node already has a Twitter paragraph.
$hasTwitterParagraph = FALSE;
if ($node->hasField('field_paragraphs') && !$node->get('field_paragraphs')->isEmpty()) {
foreach ($node->get('field_paragraphs') as $item) {
$paragraph = $item->entity;
if ($paragraph && $paragraph->bundle() == 'social_media_sites') {
$siteField = $paragraph->get('field_site')->getValue();
if (!empty($siteField) && $siteField[0]['target_id'] == $twitter_term->id()) {
$hasTwitterParagraph = TRUE;
break;
}
}
}
}
if ($hasTwitterParagraph) {
\Drupal::messenger()->addStatus(t('Node @nid already has a Twitter paragraph; skipping migration.', ['@nid' => $node->id()]));
// Clear the old field anyway.
$node->set('field_twitter_account', NULL);
$node->save();
continue;
}

// Process the migration if no Twitter paragraph exists.
$link_item = $node->get('field_twitter_account')->first();
if ($link_item) {
$uri = $link_item->uri;
$handle = $link_item->title;

// Create a new paragraph of type social_media_sites.
$paragraph = Paragraph::create([
'type' => 'social_media_sites',
// Set all field values before saving.
'field_text' => $handle,
'field_link' => [
'uri' => $uri,
'title' => $handle,
],
'field_site' => [
['target_id' => $twitter_term->id()],
],
]);
$paragraph->save();

// Attach the paragraph to the node's field_paragraphs field.
if ($node->hasField('field_paragraphs')) {
$node->get('field_paragraphs')->appendItem([
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
]);
// Optionally, clear the old field_twitter_account.
$node->set('field_twitter_account', NULL);
$node->save();
$migrated_nids[] = $node->id();
}
}
}
}

if (!empty($migrated_nids)) {
$message = t('Migrated Twitter account values for node IDs: @nids', ['@nids' => implode(', ', $migrated_nids)]);
\Drupal::messenger()->addStatus($message);
}
else {
\Drupal::messenger()->addStatus(t('No nodes were migrated.'));
}
return t('Migrated field_twitter_account values to social_media_sites paragraphs for applicable nodes.');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
langcode: en
status: true
dependencies:
config:
- field.field.paragraph.social_media_sites.field_link
- field.field.paragraph.social_media_sites.field_site
- field.field.paragraph.social_media_sites.field_text
- paragraphs.paragraphs_type.social_media_sites
module:
- link
id: paragraph.social_media_sites.default
targetEntityType: paragraph
bundle: social_media_sites
mode: default
content:
field_link:
type: link_default
weight: 3
region: content
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
field_site:
type: options_select
weight: 0
region: content
settings: { }
third_party_settings: { }
field_text:
type: string_textfield
weight: 2
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden:
created: true
status: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
langcode: en
status: true
dependencies:
config:
- field.field.paragraph.social_media_sites.field_link
- field.field.paragraph.social_media_sites.field_site
- field.field.paragraph.social_media_sites.field_text
- paragraphs.paragraphs_type.social_media_sites
module:
- ds
- link
id: paragraph.social_media_sites.default
targetEntityType: paragraph
bundle: social_media_sites
mode: default
content:
field_link:
type: link
label: hidden
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
weight: 4
region: content
field_site:
type: entity_reference_entity_view
label: hidden
settings:
view_mode: default
link: false
third_party_settings: { }
weight: 0
region: content
field_text:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings:
ds:
ft:
id: minimal
settings:
lb: ''
lb-col: false
classes: { }
weight: 2
region: content
hidden:
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.paragraph.preview
- field.field.paragraph.social_media_sites.field_link
- field.field.paragraph.social_media_sites.field_site
- field.field.paragraph.social_media_sites.field_text
- paragraphs.paragraphs_type.social_media_sites
module:
- ds
id: paragraph.social_media_sites.preview
targetEntityType: paragraph
bundle: social_media_sites
mode: preview
content:
field_text:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings:
ds:
ft:
id: minimal
settings:
lb: ''
lb-col: false
classes: { }
weight: 2
region: content
hidden:
field_link: true
field_site: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_link
- paragraphs.paragraphs_type.social_media_sites
module:
- link
id: paragraph.social_media_sites.field_link
field_name: field_link
entity_type: paragraph
bundle: social_media_sites
label: URL
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
title: 0
link_type: 17
field_type: link
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_site
- paragraphs.paragraphs_type.social_media_sites
- taxonomy.vocabulary.social_media_sites
id: paragraph.social_media_sites.field_site
field_name: field_site
entity_type: paragraph
bundle: social_media_sites
label: Site
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
social_media_sites: social_media_sites
sort:
field: name
direction: asc
auto_create: false
auto_create_bundle: ''
field_type: entity_reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_text
- paragraphs.paragraphs_type.social_media_sites
id: paragraph.social_media_sites.field_text
field_name: field_text
entity_type: paragraph
bundle: social_media_sites
label: Handle
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
langcode: en
status: true
dependencies:
module:
- paragraphs
- taxonomy
id: paragraph.field_site
field_name: field_site
entity_type: paragraph
type: entity_reference
settings:
target_type: taxonomy_term
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
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies: { }
id: social_media_sites
label: 'Social Media Sites'
icon_uuid: null
icon_default: null
description: ''
behavior_plugins: { }
Loading