From 5456cf70c40ca369f2c57a5d70f3ae814ff84e6b Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 25 Apr 2024 13:00:12 -0700 Subject: [PATCH 01/48] Issue #12 adding an and phrase for listings. --- modules/wri_common/wri_common.module | 2 +- modules/wri_node/config/schema/wri_node.schema.yml | 3 +++ modules/wri_node/src/Form/SettingsForm.php | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index b87b8d853..fc4cd3b17 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -337,7 +337,7 @@ function _wri_common_format_list(array $terms) { // If there is more than 1 term, build a list. if (count($terms) > 1) { if (!next($terms)) { - $list .= "and $term_name"; + $list .= \Drupal::config('wri_node.settings')->get('and_phrase') . " $term_name"; } else { $list .= "$term_name, "; diff --git a/modules/wri_node/config/schema/wri_node.schema.yml b/modules/wri_node/config/schema/wri_node.schema.yml index 1c57c0fb7..dafef6ae3 100644 --- a/modules/wri_node/config/schema/wri_node.schema.yml +++ b/modules/wri_node/config/schema/wri_node.schema.yml @@ -20,3 +20,6 @@ wri_node.settings: twitter_share_suffix: type: text label: 'Twitter Share suffix' + and_phrase: + type: text + label: 'And word for listings, ie: 1, 2 "and" 3' diff --git a/modules/wri_node/src/Form/SettingsForm.php b/modules/wri_node/src/Form/SettingsForm.php index 8aadfd82b..b0fb11470 100644 --- a/modules/wri_node/src/Form/SettingsForm.php +++ b/modules/wri_node/src/Form/SettingsForm.php @@ -74,6 +74,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#required' => TRUE, ]; + $form['and_phrase'] = [ + '#type' => 'textfield', + '#title' => $this->t('And word for listings, ie: 1, 2 "and" 3'), + '#default_value' => $this->config('wri_node.settings')->get('and_phrase'), + '#required' => TRUE, + ]; + $form['person_listing_url'] = [ '#type' => 'textfield', '#title' => $this->t('Person listing url'), From 5b8509a3641dc645bc44c1084f9e36b308acc0be Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 25 Apr 2024 13:46:42 -0700 Subject: [PATCH 02/48] Issue #12 saving the config. --- modules/wri_node/src/Form/SettingsForm.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/wri_node/src/Form/SettingsForm.php b/modules/wri_node/src/Form/SettingsForm.php index b0fb11470..87ef2732f 100644 --- a/modules/wri_node/src/Form/SettingsForm.php +++ b/modules/wri_node/src/Form/SettingsForm.php @@ -123,6 +123,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->set('use_fallback_image', $form_state->getValue('use_fallback_image')) ->set('unpublished_person_phrase', $form_state->getValue('unpublished_person_phrase')) ->set('person_listing_url', $form_state->getValue('person_listing_url')) + ->set('and_phrase', $form_state->getValue('and_phrase')) ->set('disable_ads_data_redaction', $form_state->getValue('disable_ads_data_redaction')) ->set('disable_osano_script', $form_state->getValue('disable_osano_script')) ->set('twitter_share_suffix', $form_state->getValue('twitter_share_suffix')) From e2de5ea568026e1f3090caf8689da8ac4cf00169 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 25 Apr 2024 14:17:42 -0700 Subject: [PATCH 03/48] Issue #12 refactoring person links. --- modules/wri_common/wri_common.module | 73 ++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index fc4cd3b17..9b51957d3 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -157,6 +157,14 @@ function wri_common_token_info() { 'name' => 'A node link', 'description' => 'The link to the node, if published, or its title if not.', ]; + $info['tokens']['node']['projects_links'] = [ + 'name' => 'A listing of project links', + 'description' => 'The link to the related projects if published, and the site title if no projects are related.', + ]; + $info['tokens']['node']['primary_contact_links'] = [ + 'name' => 'The primary contact link or a fallback phrase.', + 'description' => 'The link to the related primary contact if published, and a fallback phrase if no published contact found.', + ]; $info['tokens']['taxonomy_term']['link'] = [ 'name' => 'A term link', 'description' => 'The link to the term, if published, or its title if not.', @@ -234,6 +242,25 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab switch ($name) { case 'link': $replacements[$original] = wri_common_link_or_text($data['node']); + break; + case 'projects_links': + if ($node->hasField('field_projects') && ($contact_items = $node->get('field_projects')) && !$contact_items->isEmpty()) { + $contact_item = $contact_items->first()->entity; + $replacements[$original] = wri_common_link_or_text($contact_item); + } + else { + $replacements[$original] = \Drupal::config('system.site')->get('name'); + } + break; + case 'primary_contact_links': + if ($node->hasField('field_primary_contacts') && ($contact_items = $node->get('field_primary_contacts')) && !$contact_items->isEmpty()) { + $contact_item = $contact_items->first()->entity; + $replacements[$original] = wri_common_link_or_text($contact_item); + } + else { + $replacements[$original] = \Drupal::config('wri_node.settings')->get('unpublished_person_phrase'); + } + break; } } } @@ -370,28 +397,9 @@ function wri_common_link_or_text(EntityInterface $entity) { } else { if ($entity->bundle() == 'person') { - $url = Url::fromUserInput(\Drupal::config('wri_node.settings')->get('person_listing_url')); - // See if the current page is a node. $node = \Drupal::routeMatch()->getParameter('node'); - if ($node instanceof NodeInterface) { - // If the current page is a project, link to its experts page. - if ($node->bundle() == 'project_detail') { - $url = Url::fromUserInput('/project-experts/' . $node->id()); - } - // Otherwise, see if that node has a 'field_projects', and THAT node - // is published. - elseif ($node->hasField('field_projects')) { - $project = $node->field_projects->entity; - if ($project && $project->isPublished()) { - // If it is, link to the projects/experts page. - $url = Url::fromUserInput('/project-experts/' . $node->field_projects->target_id); - } - } - } - - // Fallback to the /about/experts page. - $link = Link::fromTextAndUrl(\Drupal::config('wri_node.settings')->get('unpublished_person_phrase'), $url)->toString(); + $link = wri_common_person_link_fallback($node); } else { $link = $entity->label(); @@ -401,6 +409,31 @@ function wri_common_link_or_text(EntityInterface $entity) { return $link; } +function wri_common_person_link_fallback(EntityInterface $node) { + $url = Url::fromUserInput(\Drupal::config('wri_node.settings')->get('person_listing_url')); + + if ($node instanceof NodeInterface) { + // If the current page is a project, link to its experts page. + if ($node->bundle() == 'project_detail') { + $url = Url::fromUserInput('/project-experts/' . $node->id()); + } + // Otherwise, see if that node has a 'field_projects', and THAT node + // is published. + elseif ($node->hasField('field_projects')) { + $project = $node->field_projects->entity; + if ($project && $project->isPublished()) { + // If it is, link to the projects/experts page. + $url = Url::fromUserInput('/project-experts/' . $node->field_projects->target_id); + } + } + } + + // Fallback to the /about/experts page. + $link = Link::fromTextAndUrl(\Drupal::config('wri_node.settings')->get('unpublished_person_phrase'), $url)->toString(); + + return $link; +} + /** * Implements hook_page_attachments_alter(). */ From 5f3524ccdbe2a80319fe442ebac1224ba870e817 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 25 Apr 2024 14:41:45 -0700 Subject: [PATCH 04/48] Issue #12 handling unpublished terms and nodes in the list builder. --- modules/wri_common/wri_common.module | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 9b51957d3..793024bea 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -244,9 +244,8 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $replacements[$original] = wri_common_link_or_text($data['node']); break; case 'projects_links': - if ($node->hasField('field_projects') && ($contact_items = $node->get('field_projects')) && !$contact_items->isEmpty()) { - $contact_item = $contact_items->first()->entity; - $replacements[$original] = wri_common_link_or_text($contact_item); + if ($node->hasField('field_projects') && ($projects = $node->get('field_projects')->referencedEntities())) { + $replacements[$original] = _wri_common_format_list($projects); } else { $replacements[$original] = \Drupal::config('system.site')->get('name'); @@ -293,10 +292,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab function wri_common_get_node_topics(Node $node, $secondary_only = FALSE) { $topics = []; if (!$secondary_only && $node->hasField('field_primary_topic') && ($topic_items = $node->get('field_primary_topic')) && !$topic_items->isEmpty()) { - $topic_item = $topic_items->first()->entity; - if ($topic_item && $topic_item->isPublished()) { - $topics[] = $topic_item; - } + $topics[] = $topic_items->first()->entity; } if ($node->hasField('field_tags') && ($tag_items = $node->get('field_tags')) && !$tag_items->isEmpty()) { foreach ($tag_items as $tag_item) { @@ -348,19 +344,26 @@ function _wri_common_format_list(array $terms) { $list = ''; if ($terms) { foreach ($terms as $term) { - $term_url = $term->toUrl(); - if ($term->hasField('field_full_name') && $term_label = $term->get('field_full_name')->getString()) { - if ($term_url->toString()) { - $term_name = Link::fromTextAndUrl($term_label, $term_url) - ->toRenderable(); - $renderer = \Drupal::service('renderer'); - $term_name = $renderer->render($term_name); + $published = $term->isPublished(); + if ($published) { + $term_url = $term->toUrl(); + if ($term->hasField('field_full_name') && $term_label = $term->get('field_full_name')->getString()) { + if ($term_url->toString()) { + $term_name = Link::fromTextAndUrl($term_label, $term_url) + ->toRenderable(); + $renderer = \Drupal::service('renderer'); + $term_name = $renderer->render($term_name); + } + } + else { + $term_name = $term->toLink()->tostring(); } } else { - $term_name = $term->toLink()->tostring(); + $term_name = $term->label(); } + // If there is more than 1 term, build a list. if (count($terms) > 1) { if (!next($terms)) { From 0eae9ca1c0d82456137448395bb72e252fab8ab5 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Wed, 1 May 2024 15:05:34 -0700 Subject: [PATCH 05/48] The simplest config collection import rule. --- modules/wri_node/wri_node.install | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index c5f91a9dd..4d431f00f 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -38,3 +38,12 @@ function wri_node_update_9503() { 'osano_params', ], 'wri_admin'); } + +/** + * Updates the node and_phrase values. + */ +function wri_node_update_10001() { + \Drupal::service('distro_helper.updates')->updateConfig('wri_node.settings', [ + 'and_phrase', + ], 'wri_node', 'install'); +} \ No newline at end of file From ce012de40deba0b8c1e765a134975e5a48f30f15 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Wed, 1 May 2024 15:37:15 -0700 Subject: [PATCH 06/48] Attempting to save config values by language #12. --- modules/wri_node/wri_node.install | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 4d431f00f..711b1fd7c 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -46,4 +46,35 @@ function wri_node_update_10001() { \Drupal::service('distro_helper.updates')->updateConfig('wri_node.settings', [ 'and_phrase', ], 'wri_node', 'install'); -} \ No newline at end of file + + $collections = \Drupal::service('config.manager')->getConfigCollectionInfo(); + foreach ($collections->getCollectionNames() as $collection_name) { + if ($collection_name) { + $collection = $collections->getOverrideService($collection_name); + $language = $collection->getLanguage()->getId(); + $config_translation = \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings'); + switch ($language) { + case 'en': + $config_translation->set('and_phrase', 'and'); + break; + case 'fr': + $config_translation->set('and_phrase', 'et'); + break; + case 'es': + $config_translation->set('and_phrase', 'y'); + break; + case 'zh-hans': + $config_translation->set('and_phrase', '和'); + break; + case 'id': + $config_translation->set('and_phrase', 'dan'); + break; + case 'pt-br': + $config_translation->set('and_phrase', 'e'); + break; + } + // Write the keys you want to translate on the config object. + $config_translation->save(); + } + } +} From 214afb8c19b1191964e79f72af7af128e9f25fae Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Wed, 1 May 2024 16:48:45 -0700 Subject: [PATCH 07/48] Issue #12 adding the update hook for each language. --- modules/wri_node/wri_node.install | 64 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 711b1fd7c..d01a5453c 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -43,38 +43,44 @@ function wri_node_update_9503() { * Updates the node and_phrase values. */ function wri_node_update_10001() { - \Drupal::service('distro_helper.updates')->updateConfig('wri_node.settings', [ - 'and_phrase', - ], 'wri_node', 'install'); - $collections = \Drupal::service('config.manager')->getConfigCollectionInfo(); + foreach ($collections->getCollectionNames() as $collection_name) { if ($collection_name) { - $collection = $collections->getOverrideService($collection_name); - $language = $collection->getLanguage()->getId(); - $config_translation = \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings'); - switch ($language) { - case 'en': - $config_translation->set('and_phrase', 'and'); - break; - case 'fr': - $config_translation->set('and_phrase', 'et'); - break; - case 'es': - $config_translation->set('and_phrase', 'y'); - break; - case 'zh-hans': - $config_translation->set('and_phrase', '和'); - break; - case 'id': - $config_translation->set('and_phrase', 'dan'); - break; - case 'pt-br': - $config_translation->set('and_phrase', 'e'); - break; - } - // Write the keys you want to translate on the config object. - $config_translation->save(); + list(, $language) = explode('.', $collection_name); + } + else { + $config_translation = \Drupal::configFactory()->getEditable('wri_node.settings'); + $language = $default_language = $config_translation->get('langcode'); + } + $phrase = 'and'; + + switch ($language) { + case 'en': + $phrase = 'and'; + break; + case 'fr': + $phrase = 'et'; + break; + case 'es': + $phrase = 'y'; + break; + case 'zh-hans': + $phrase = '和'; + break; + case 'id': + $phrase = 'dan'; + break; + case 'pt-br': + $phrase = 'e'; + break; + } + + if ($collection_name && $default_language != $language) { + \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings')->set('and_phrase', $phrase)->save(); + } + else { + \Drupal::configFactory()->getEditable('wri_node.settings')->set('and_phrase', $phrase)->save(); } } } From 594a9803500d6b2aebf81f6279b6205401a92aed Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Tue, 14 May 2024 17:26:17 -0700 Subject: [PATCH 08/48] Issue #12 translated narrative taxonomies proof of concept. --- ...roject_detail.field_narrative_taxonomy.yml | 28 +++++++++++++++++++ ...roject_detail.field_narrative_taxonomy.yml | 27 ++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml create mode 100644 modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml diff --git a/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml new file mode 100644 index 000000000..7fe1c64cb --- /dev/null +++ b/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -0,0 +1,28 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_narrative_taxonomy + - node.type.project_detail + module: + - allowed_formats + - text +third_party_settings: + allowed_formats: + allowed_formats: + - basic_html +id: node.project_detail.field_narrative_taxonomy +field_name: field_narrative_taxonomy +entity_type: node +bundle: project_detail +label: 'Narrative Taxonomy' +description: 'If you want to use the default value, choose "Source" and paste: <p>WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:field_primary_contacts:entity:link] for more details or media inquiries.</p>' +required: false +translatable: true +default_value: + - + value: "

WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:field_primary_contacts:entity:link] for more details or media inquiries.

\r\n" + format: basic_html +default_value_callback: '' +settings: { } +field_type: text_long diff --git a/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml new file mode 100644 index 000000000..5f0fd3c3d --- /dev/null +++ b/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -0,0 +1,27 @@ +uuid: e6cb7390-959f-4165-a60f-31fd4c3d41fd +langcode: es +status: true +dependencies: + config: + - field.storage.node.field_narrative_taxonomy + - filter.format.basic_html + - node.type.project_detail + module: + - text +id: node.project_detail.field_narrative_taxonomy +field_name: field_narrative_taxonomy +entity_type: node +bundle: project_detail +label: 'Narrative Taxonomy' +description: 'If you want to use the default value, choose "Source" and paste: <p><span>El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:field_primary_contacts:entity:link].</span></p>' +required: false +translatable: true +default_value: + - + value: '

El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:field_primary_contacts:entity:link].

' + format: basic_html +default_value_callback: '' +settings: + allowed_formats: + - basic_html +field_type: text_long From 6a0245dac5118053e81da2ab09d2e4c5b9ef7547 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:02:01 -0700 Subject: [PATCH 09/48] Spanish translation update. --- ...ield.field.node.project_detail.field_narrative_taxonomy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml index 5f0fd3c3d..60729fa40 100644 --- a/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml +++ b/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -1,4 +1,3 @@ -uuid: e6cb7390-959f-4165-a60f-31fd4c3d41fd langcode: es status: true dependencies: @@ -13,7 +12,7 @@ field_name: field_narrative_taxonomy entity_type: node bundle: project_detail label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p><span>El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:field_primary_contacts:entity:link].</span></p>' +description: 'Si desea utilizar el valor predeterminado, elija "Origen" y pegue: <p><span>El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:field_primary_contacts:entity:link].</span></p>' required: false translatable: true default_value: From dc64fe7eacd3a789f224e14d054e701fbb9215b7 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:05:52 -0700 Subject: [PATCH 10/48] Issue #12 updating all primary contact links to use the new pattern. --- .../field.field.node.data.field_narrative_taxonomy.yml | 4 ++-- modules/wri_narrative/wri_narrative.post_update.php | 2 +- ...eld.field.node.project_detail.field_narrative_taxonomy.yml | 4 ++-- ...eld.field.node.project_detail.field_narrative_taxonomy.yml | 4 ++-- ...eld.field.node.project_detail.field_narrative_taxonomy.yml | 4 ++-- .../field.field.node.publication.field_narrative_taxonomy.yml | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml b/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml index 5cea5bd17..577c65233 100644 --- a/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml +++ b/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: data label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:field_primary_contacts:entity:link] for more information.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' required: false translatable: true default_value: - - value: "

This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:field_primary_contacts:entity:link] for more information.

\r\n" + value: "

This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" format: basic_html default_value_callback: '' settings: { } diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index 59fd9c5ff..2122e0110 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -54,7 +54,7 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies(&$sandbox) { '[node:field_featured_experts:entity]', ], ['[node:field_projects:entity:link]', - '[node:field_primary_contacts:entity:link]', + '[node:primary_contact_links]', '[node:field_featured_experts:entity:link]', ], $taxonomy_value[0]['value'] diff --git a/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml index 7fe1c64cb..ed8d2639f 100644 --- a/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml +++ b/modules/wri_project/config/install/en/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: project_detail label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:field_primary_contacts:entity:link] for more details or media inquiries.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:primary_contact_links] for more details or media inquiries.</p>' required: false translatable: true default_value: - - value: "

WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:field_primary_contacts:entity:link] for more details or media inquiries.

\r\n" + value: "

WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:primary_contact_links] for more details or media inquiries.

\r\n" format: basic_html default_value_callback: '' settings: { } diff --git a/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml index 60729fa40..26e8f6fec 100644 --- a/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml +++ b/modules/wri_project/config/install/es/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -12,12 +12,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: project_detail label: 'Narrative Taxonomy' -description: 'Si desea utilizar el valor predeterminado, elija "Origen" y pegue: <p><span>El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:field_primary_contacts:entity:link].</span></p>' +description: 'Si desea utilizar el valor predeterminado, elija "Origen" y pegue: <p><span>El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:primary_contact_links].</span></p>' required: false translatable: true default_value: - - value: '

El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:field_primary_contacts:entity:link].

' + value: '

El proyecto [node:title] es parte del programa de [wri_tokens:topic_and_sub_topic_links_list]. Para más información, favor de contactar a [node:primary_contact_links].

' format: basic_html default_value_callback: '' settings: diff --git a/modules/wri_project/config/install/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/field.field.node.project_detail.field_narrative_taxonomy.yml index 7fe1c64cb..ed8d2639f 100644 --- a/modules/wri_project/config/install/field.field.node.project_detail.field_narrative_taxonomy.yml +++ b/modules/wri_project/config/install/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: project_detail label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:field_primary_contacts:entity:link] for more details or media inquiries.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:primary_contact_links] for more details or media inquiries.</p>' required: false translatable: true default_value: - - value: "

WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:field_primary_contacts:entity:link] for more details or media inquiries.

\r\n" + value: "

WRI's [node:title] is part of [wri_tokens:topic_and_sub_topic_links_list]. Contact [node:primary_contact_links] for more details or media inquiries.

\r\n" format: basic_html default_value_callback: '' settings: { } diff --git a/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml b/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml index 694881a5b..f0db6e0d8 100644 --- a/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml +++ b/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: publication label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:field_primary_contacts:entity:link] for more information.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' required: false translatable: true default_value: - - value: "

This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:field_primary_contacts:entity:link] for more information.

\r\n" + value: "

This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" format: basic_html default_value_callback: '' settings: { } From 60f77ad5952ddd34fe42e5019fa5b1edae90f5a0 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:11:53 -0700 Subject: [PATCH 11/48] Issue #12 updating narrative taxonomies to use new tokens. --- .../field.field.node.data.field_narrative_taxonomy.yml | 4 ++-- modules/wri_narrative/wri_narrative.post_update.php | 2 +- .../field.field.node.publication.field_narrative_taxonomy.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml b/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml index 577c65233..1990b81b6 100644 --- a/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml +++ b/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: data label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' required: false translatable: true default_value: - - value: "

This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" + value: "

This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" format: basic_html default_value_callback: '' settings: { } diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index 2122e0110..c3ef1d9c1 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -53,7 +53,7 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies(&$sandbox) { '[node:field_primary_contacts:entity]', '[node:field_featured_experts:entity]', ], - ['[node:field_projects:entity:link]', + ['[node:projects_links]', '[node:primary_contact_links]', '[node:field_featured_experts:entity:link]', ], diff --git a/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml b/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml index f0db6e0d8..8fe024d61 100644 --- a/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml +++ b/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: publication label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' required: false translatable: true default_value: - - value: "

This [node:field_type:entity] is part of the [node:field_projects:entity:link] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" + value: "

This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" format: basic_html default_value_callback: '' settings: { } From 536f0aab39752c8e9e11f199e4777d2a61e67f7a Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:20:14 -0700 Subject: [PATCH 12/48] Adding new update hook. --- .../wri_narrative.post_update.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index c3ef1d9c1..b944feb39 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -71,3 +71,66 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies(&$sandbox) { $sandbox['#finished'] = ($sandbox['current'] == $start_value); } + +/** + * Updates the tokens in narrative taxonomies, round 2. + */ +function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { + if (!isset($sandbox['total'])) { + $sandbox['total'] = Drupal::database()->select('node__field_narrative_taxonomy', 'u') + ->condition('u.field_narrative_taxonomy_value', '[node:field_(projects|primary_contacts):entity:link]', 'REGEXP') + ->fields('u') + ->countQuery() + ->execute() + ->fetchField(); + $sandbox['current'] = 0; + + if (empty($sandbox['total'])) { + $sandbox['#finished'] = 1; + return; + } + } + + $users_per_batch = 25; + $start_value = $sandbox['current']; + $nids = Drupal::database()->select('node__field_narrative_taxonomy', 'u') + ->condition('u.field_narrative_taxonomy_value', '[node:field_(projects|primary_contacts):entity:link]', 'REGEXP') + ->condition('entity_id', $sandbox['current'], '>=') + ->fields('u') + ->orderBy('entity_id') + ->range(0, $users_per_batch) + ->execute(); + + if (empty($nids)) { + $sandbox['#finished'] = 1; + return; + } + // Loop through each node. + foreach ($nids as $result) { + $node = Node::load($result->entity_id); + if ($node->hasTranslation($result->langcode)) { + $node = $node->getTranslation($result->langcode); + } + $taxonomy_value = $node->field_narrative_taxonomy->getValue(); + // Replace link strings with new values. + $taxonomy_value[0]['value'] = str_replace( + ['[node:field_primary_contacts:entity:link]', + '[node:field_projects:entity:link]', + ], + [ '[node:primary_contact_links]', + '[node:projects_links]' + ], + $taxonomy_value[0]['value'] + ); + $node->field_narrative_taxonomy->setValue($taxonomy_value); + + // Save the node. + $node->save(); + $sandbox['current'] = $result->entity_id; + } + + \Drupal::messenger() + ->addMessage($sandbox['current'] . ' node last processed.'); + + $sandbox['#finished'] = ($sandbox['current'] == $start_value); +} \ No newline at end of file From fcfc2a90bb4a0a928926e89bdacad59ca6ef155b Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:26:01 -0700 Subject: [PATCH 13/48] Issue #12 brackets mean something in regex. --- modules/wri_narrative/wri_narrative.post_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index b944feb39..2e61c05de 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -94,7 +94,7 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { $users_per_batch = 25; $start_value = $sandbox['current']; $nids = Drupal::database()->select('node__field_narrative_taxonomy', 'u') - ->condition('u.field_narrative_taxonomy_value', '[node:field_(projects|primary_contacts):entity:link]', 'REGEXP') + ->condition('u.field_narrative_taxonomy_value', '\[node:field_(projects|primary_contacts):entity:link\]', 'REGEXP') ->condition('entity_id', $sandbox['current'], '>=') ->fields('u') ->orderBy('entity_id') From e8c42c3c0c4642a1a3a6820e6a16a11e0774dc76 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:32:43 -0700 Subject: [PATCH 14/48] Indonesian translation. --- ...roject_detail.field_narrative_taxonomy.yml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml diff --git a/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml new file mode 100644 index 000000000..1a35df026 --- /dev/null +++ b/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -0,0 +1,28 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_narrative_taxonomy + - node.type.project_detail + module: + - allowed_formats + - text +third_party_settings: + allowed_formats: + allowed_formats: + - basic_html +id: node.project_detail.field_narrative_taxonomy +field_name: field_narrative_taxonomy +entity_type: node +bundle: project_detail +label: 'Narrative Taxonomy' +description: 'Jika Anda ingin menggunakan nilai default, pilih "Sumber" dan tempel: <p>WRI's [node:title] adalah bagian dari [wri_tokens:topic_and_sub_topic_links_list]. Hubungi [node:primary_contact_links] untuk detail lebih lanjut atau pertanyaan media.</p>' +required: false +translatable: true +default_value: + - + value: "

WRI's [node:title] adalah bagian dari [wri_tokens:topic_and_sub_topic_links_list]. Hubungi [node:primary_contact_links] untuk detail lebih lanjut atau pertanyaan media.

\r\n" + format: basic_html +default_value_callback: '' +settings: { } +field_type: text_long From fb3e09a476b02bd87df81f3730931173574ab771 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:39:41 -0700 Subject: [PATCH 15/48] Translating all languages #12. --- ...roject_detail.field_narrative_taxonomy.yml | 2 +- ...roject_detail.field_narrative_taxonomy.yml | 26 +++++++++++++++++ ...roject_detail.field_narrative_taxonomy.yml | 28 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 modules/wri_project/config/install/pt-br/field.field.node.project_detail.field_narrative_taxonomy.yml create mode 100644 modules/wri_project/config/install/zh-hans/field.field.node.project_detail.field_narrative_taxonomy.yml diff --git a/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml index 1a35df026..a083f306e 100644 --- a/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml +++ b/modules/wri_project/config/install/id/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -1,4 +1,4 @@ -langcode: en +langcode: id status: true dependencies: config: diff --git a/modules/wri_project/config/install/pt-br/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/pt-br/field.field.node.project_detail.field_narrative_taxonomy.yml new file mode 100644 index 000000000..eff1b5a54 --- /dev/null +++ b/modules/wri_project/config/install/pt-br/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -0,0 +1,26 @@ +langcode: pt-br +status: true +dependencies: + config: + - field.storage.node.field_narrative_taxonomy + - filter.format.basic_html + - node.type.project_detail + module: + - text +id: node.project_detail.field_narrative_taxonomy +field_name: field_narrative_taxonomy +entity_type: node +bundle: project_detail +label: 'Narrative Taxonomy' +description: 'Predefinição: escolha "Código-Fonte" e cole: O projeto [node:title] faz parte do programa de [wri_tokens:topic_and_sub_topic_links_list]. Para informações sobre o projeto, contate [node:field_primary_contacts:entity:link]. Para solicitar uma entrevista, visite a página de <a href="/imprensa">imprensa</a>.' +required: false +translatable: true +default_value: + - + value: 'O projeto [node:title] faz parte do programa de [wri_tokens:topic_and_sub_topic_links_list]. Para informações sobre o projeto, contate [node:field_primary_contacts:entity:link]. Para solicitar uma entrevista, visite a página de imprensa.' + format: basic_html +default_value_callback: '' +settings: + allowed_formats: + - basic_html +field_type: text_long diff --git a/modules/wri_project/config/install/zh-hans/field.field.node.project_detail.field_narrative_taxonomy.yml b/modules/wri_project/config/install/zh-hans/field.field.node.project_detail.field_narrative_taxonomy.yml new file mode 100644 index 000000000..58cb12d44 --- /dev/null +++ b/modules/wri_project/config/install/zh-hans/field.field.node.project_detail.field_narrative_taxonomy.yml @@ -0,0 +1,28 @@ +langcode: zh-hans +status: true +dependencies: + config: + - field.storage.node.field_narrative_taxonomy + - node.type.project_detail + module: + - allowed_formats + - text +third_party_settings: + allowed_formats: + allowed_formats: + - basic_html +id: node.project_detail.field_narrative_taxonomy +field_name: field_narrative_taxonomy +entity_type: node +bundle: project_detail +label: 'Narrative Taxonomy' +description: 'If you want to use the default value, choose "Source" and paste: <p>WRI's [node:title] 是 [wri_tokens:topic_and_sub_topic_links_list]. 的一部分。联系 [node:primary_contact_links] 了解更多详细信息或媒体查询。</p>' +required: false +translatable: true +default_value: + - + value: "

WRI's [node:title] 是 [wri_tokens:topic_and_sub_topic_links_list] 的一部分。联系 [node:primary_contact_links] 了解更多详细信息或媒体查询。

\r\n" + format: basic_html +default_value_callback: '' +settings: { } +field_type: text_long From c8ba5dc145aed89a7944d20ddf13e6302ae232d3 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 12:47:21 -0700 Subject: [PATCH 16/48] Getting started updating all the config values. --- modules/wri_node/wri_node.install | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index d01a5453c..39859da5c 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -47,7 +47,7 @@ function wri_node_update_10001() { foreach ($collections->getCollectionNames() as $collection_name) { if ($collection_name) { - list(, $language) = explode('.', $collection_name); + [, $language] = explode('.', $collection_name); } else { $config_translation = \Drupal::configFactory()->getEditable('wri_node.settings'); @@ -84,3 +84,28 @@ function wri_node_update_10001() { } } } + +/** + * Add translations for each narrative taxonomy language. + */ +function wri_node_update_10002() { + // Load all narrative taxonomy fields on nodes. + $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative']); + $old_values = [ + '[node:field_primary_contacts:entity:link]', + '[node:field_projects:entity:link]', + ]; + $new_values = [ + '[node:primary_contact_links]', + '[node:projects_links]' + ]; + + // Loop through the fields. + foreach ($narrative_fields as $narrative_field) { + // Find and replace the tokens. + $narrative_field->description = str_replace('narrative', 'narrative', $narrative_field->description); + $narrative_field->default_value[0]['value'] = str_replace($old_values, $new_values, $narrative_field->default_value[0]['value']); + + $narrative_field->save(); + } +} \ No newline at end of file From e5a3b9c5d26166af2f22effa502da7eeee3bfc23 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 13:02:51 -0700 Subject: [PATCH 17/48] Issue #12 replacing tokens in narrative taxonomies. --- modules/wri_node/wri_node.install | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 39859da5c..3536c9e08 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -85,12 +85,13 @@ function wri_node_update_10001() { } } + /** * Add translations for each narrative taxonomy language. */ function wri_node_update_10002() { // Load all narrative taxonomy fields on nodes. - $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative']); + $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ '[node:field_primary_contacts:entity:link]', '[node:field_projects:entity:link]', @@ -102,10 +103,15 @@ function wri_node_update_10002() { // Loop through the fields. foreach ($narrative_fields as $narrative_field) { + $field = \Drupal::configFactory()->getEditable('field.field.' . $narrative_field->id()); // Find and replace the tokens. - $narrative_field->description = str_replace('narrative', 'narrative', $narrative_field->description); - $narrative_field->default_value[0]['value'] = str_replace($old_values, $new_values, $narrative_field->default_value[0]['value']); + $field->set('description', str_replace($old_values, $new_values, $field->get('description'))); + $default_value = $field->get('default_value'); + if (isset($default_value[0]['value'])) { + $default_value[0]['value'] = str_replace($old_values, $new_values, $default_value[0]['value']); + $field->set('default_value', $default_value); + } - $narrative_field->save(); + $field->save(); } } \ No newline at end of file From 8ac82db478f4092ebaafedaac44870701c237d1a Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 13:07:22 -0700 Subject: [PATCH 18/48] PHPCS. --- modules/wri_common/wri_common.module | 12 +++++++++++- modules/wri_narrative/wri_narrative.post_update.php | 6 +++--- modules/wri_node/src/Form/SettingsForm.php | 2 +- modules/wri_node/wri_node.install | 12 ++++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 793024bea..dadfab99c 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -243,6 +243,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'link': $replacements[$original] = wri_common_link_or_text($data['node']); break; + case 'projects_links': if ($node->hasField('field_projects') && ($projects = $node->get('field_projects')->referencedEntities())) { $replacements[$original] = _wri_common_format_list($projects); @@ -251,6 +252,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $replacements[$original] = \Drupal::config('system.site')->get('name'); } break; + case 'primary_contact_links': if ($node->hasField('field_primary_contacts') && ($contact_items = $node->get('field_primary_contacts')) && !$contact_items->isEmpty()) { $contact_item = $contact_items->first()->entity; @@ -363,7 +365,6 @@ function _wri_common_format_list(array $terms) { $term_name = $term->label(); } - // If there is more than 1 term, build a list. if (count($terms) > 1) { if (!next($terms)) { @@ -412,6 +413,15 @@ function wri_common_link_or_text(EntityInterface $entity) { return $link; } +/** + * Fallback for when a person is unpublished. + * + * @param \Drupal\Core\Entity\EntityInterface $node + * The person node. + * + * @return \Drupal\Core\GeneratedLink + * The link. + */ function wri_common_person_link_fallback(EntityInterface $node) { $url = Url::fromUserInput(\Drupal::config('wri_node.settings')->get('person_listing_url')); diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index 2e61c05de..41fa21015 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -117,8 +117,8 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { ['[node:field_primary_contacts:entity:link]', '[node:field_projects:entity:link]', ], - [ '[node:primary_contact_links]', - '[node:projects_links]' + ['[node:primary_contact_links]', + '[node:projects_links]', ], $taxonomy_value[0]['value'] ); @@ -133,4 +133,4 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { ->addMessage($sandbox['current'] . ' node last processed.'); $sandbox['#finished'] = ($sandbox['current'] == $start_value); -} \ No newline at end of file +} diff --git a/modules/wri_node/src/Form/SettingsForm.php b/modules/wri_node/src/Form/SettingsForm.php index 87ef2732f..db7e3a205 100644 --- a/modules/wri_node/src/Form/SettingsForm.php +++ b/modules/wri_node/src/Form/SettingsForm.php @@ -79,7 +79,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => $this->t('And word for listings, ie: 1, 2 "and" 3'), '#default_value' => $this->config('wri_node.settings')->get('and_phrase'), '#required' => TRUE, - ]; + ]; $form['person_listing_url'] = [ '#type' => 'textfield', diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 3536c9e08..786c5c4c9 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -59,18 +59,23 @@ function wri_node_update_10001() { case 'en': $phrase = 'and'; break; + case 'fr': $phrase = 'et'; break; + case 'es': $phrase = 'y'; break; + case 'zh-hans': $phrase = '和'; break; + case 'id': $phrase = 'dan'; break; + case 'pt-br': $phrase = 'e'; break; @@ -85,7 +90,6 @@ function wri_node_update_10001() { } } - /** * Add translations for each narrative taxonomy language. */ @@ -98,7 +102,7 @@ function wri_node_update_10002() { ]; $new_values = [ '[node:primary_contact_links]', - '[node:projects_links]' + '[node:projects_links]', ]; // Loop through the fields. @@ -106,7 +110,7 @@ function wri_node_update_10002() { $field = \Drupal::configFactory()->getEditable('field.field.' . $narrative_field->id()); // Find and replace the tokens. $field->set('description', str_replace($old_values, $new_values, $field->get('description'))); - $default_value = $field->get('default_value'); + $default_value = $field->get('default_value'); if (isset($default_value[0]['value'])) { $default_value[0]['value'] = str_replace($old_values, $new_values, $default_value[0]['value']); $field->set('default_value', $default_value); @@ -114,4 +118,4 @@ function wri_node_update_10002() { $field->save(); } -} \ No newline at end of file +} From 2dd05144957fd89f3282338b395c8c088231c1c5 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 13:09:16 -0700 Subject: [PATCH 19/48] #12 what the narrative taxonomy is doing. --- modules/wri_node/wri_node.install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 786c5c4c9..2b77f6899 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -91,7 +91,7 @@ function wri_node_update_10001() { } /** - * Add translations for each narrative taxonomy language. + * Updates tokens in default value of narrative taxonomies. */ function wri_node_update_10002() { // Load all narrative taxonomy fields on nodes. From a3bd184fed928dcaf5c9f2a19464fd7e7b422110 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 13:29:32 -0700 Subject: [PATCH 20/48] Issue #12 the brackets aren't part of the description, so we can't find/replace those. --- modules/wri_node/wri_node.install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 2b77f6899..d5d12f1bb 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -97,12 +97,12 @@ function wri_node_update_10002() { // Load all narrative taxonomy fields on nodes. $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ - '[node:field_primary_contacts:entity:link]', - '[node:field_projects:entity:link]', + 'node:field_primary_contacts:entity:link', + 'node:field_projects:entity:link', ]; $new_values = [ - '[node:primary_contact_links]', - '[node:projects_links]', + 'node:primary_contact_links', + 'node:projects_links', ]; // Loop through the fields. From 7c6934b11e931f2fd092b920c0f47710608eb734 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 14:15:32 -0700 Subject: [PATCH 21/48] Issue #12 using the site name as a topic if there's none available. --- modules/wri_common/wri_common.module | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index dadfab99c..ece55c9f3 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -219,7 +219,11 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'topic_and_sub_topic_links_list': $terms = wri_common_get_node_topics($node, FALSE); - $replacements[$original] = _wri_common_format_list($terms); + if(empty($tersm)) { + $replacements[$original] = \Drupal::config('system.site')->get('name'); + } else { + $replacements[$original] = _wri_common_format_list($terms); + } break; case 'sub_topic_links_list': @@ -293,7 +297,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab */ function wri_common_get_node_topics(Node $node, $secondary_only = FALSE) { $topics = []; - if (!$secondary_only && $node->hasField('field_primary_topic') && ($topic_items = $node->get('field_primary_topic')) && !$topic_items->isEmpty()) { + if (!$secondary_only && $node->hasField('field_primary_topic') && ($topic_items = $node->get('field_primary_topic')) && !$topic_items->isEmpty() && $topic_items->first()->entity) { $topics[] = $topic_items->first()->entity; } if ($node->hasField('field_tags') && ($tag_items = $node->get('field_tags')) && !$tag_items->isEmpty()) { From 0bc9cc9a53d69f6aec490cb666e39b3ae7d7dfe6 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 14:30:31 -0700 Subject: [PATCH 22/48] Fat fingers #12. --- modules/wri_common/wri_common.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index ece55c9f3..d3d72262e 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -219,7 +219,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'topic_and_sub_topic_links_list': $terms = wri_common_get_node_topics($node, FALSE); - if(empty($tersm)) { + if(empty($terms)) { $replacements[$original] = \Drupal::config('system.site')->get('name'); } else { $replacements[$original] = _wri_common_format_list($terms); From 3e9f2092e7561bc9a9c244e980e2ddb59abd5a9f Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 14:45:24 -0700 Subject: [PATCH 23/48] Issue #12 If the contact has been deleted but there's still a reference to them, also show the unpublished phrase. --- modules/wri_common/wri_common.module | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index d3d72262e..d1a6bbe65 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -260,7 +260,12 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'primary_contact_links': if ($node->hasField('field_primary_contacts') && ($contact_items = $node->get('field_primary_contacts')) && !$contact_items->isEmpty()) { $contact_item = $contact_items->first()->entity; - $replacements[$original] = wri_common_link_or_text($contact_item); + if ($contact_item) { + $replacements[$original] = wri_common_link_or_text($contact_item); + } + else { + $replacements[$original] = \Drupal::config('wri_node.settings')->get('unpublished_person_phrase'); + } } else { $replacements[$original] = \Drupal::config('wri_node.settings')->get('unpublished_person_phrase'); From 7f7fc09d6ea69e16c4c1ac2efacd309d11e0d6dd Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 14:58:37 -0700 Subject: [PATCH 24/48] PHPCS. --- modules/wri_common/wri_common.module | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index d1a6bbe65..66cea4ab1 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -219,9 +219,10 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'topic_and_sub_topic_links_list': $terms = wri_common_get_node_topics($node, FALSE); - if(empty($terms)) { + if (empty($terms)) { $replacements[$original] = \Drupal::config('system.site')->get('name'); - } else { + } + else { $replacements[$original] = _wri_common_format_list($terms); } break; From 7a7ada0f4d3712942134c88d0a8fd56e3e52451d Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 15:37:56 -0700 Subject: [PATCH 25/48] Issue #12 fixing commas for two terms. --- modules/wri_common/wri_common.module | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 66cea4ab1..feffe3ec2 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -378,6 +378,11 @@ function _wri_common_format_list(array $terms) { // If there is more than 1 term, build a list. if (count($terms) > 1) { if (!next($terms)) { + if (count($terms) == 2) { + // Put no comma between A and B. + $list = trim ($list, ', ') . ' '; + } + // Leave the Oxford comma, A, B, and C. $list .= \Drupal::config('wri_node.settings')->get('and_phrase') . " $term_name"; } else { From ea52516ac8ecfcaa52829ab5da9427d202c2631c Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Thu, 16 May 2024 15:42:31 -0700 Subject: [PATCH 26/48] PHPCS. --- modules/wri_common/wri_common.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index feffe3ec2..e209903b1 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -380,7 +380,7 @@ function _wri_common_format_list(array $terms) { if (!next($terms)) { if (count($terms) == 2) { // Put no comma between A and B. - $list = trim ($list, ', ') . ' '; + $list = trim($list, ', ') . ' '; } // Leave the Oxford comma, A, B, and C. $list .= \Drupal::config('wri_node.settings')->get('and_phrase') . " $term_name"; From bf5eaeaddd93c71eca8a05e611dfff5e510265de Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Tue, 21 May 2024 11:10:22 -0700 Subject: [PATCH 27/48] Issue #12 linking an initiative expert if one is available. --- modules/wri_common/wri_common.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index e209903b1..6d50e512d 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -265,11 +265,11 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $replacements[$original] = wri_common_link_or_text($contact_item); } else { - $replacements[$original] = \Drupal::config('wri_node.settings')->get('unpublished_person_phrase'); + $replacements[$original] = wri_common_person_link_fallback($node); } } else { - $replacements[$original] = \Drupal::config('wri_node.settings')->get('unpublished_person_phrase'); + $replacements[$original] = wri_common_person_link_fallback($node); } break; } From c1728561e427f50c96ae40297bacdbab003e4b22 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Mon, 17 Jun 2024 13:18:37 -0700 Subject: [PATCH 28/48] Issue #12 removing the 'within' phrase. --- modules/wri_common/wri_common.module | 6 +++--- .../field.field.node.data.field_narrative_taxonomy.yml | 4 ++-- modules/wri_narrative/wri_narrative.post_update.php | 4 ++-- modules/wri_node/wri_node.install | 4 ++-- ...ield.field.node.publication.field_narrative_taxonomy.yml | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 6d50e512d..4735bf62f 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -157,8 +157,8 @@ function wri_common_token_info() { 'name' => 'A node link', 'description' => 'The link to the node, if published, or its title if not.', ]; - $info['tokens']['node']['projects_links'] = [ - 'name' => 'A listing of project links', + $info['tokens']['node']['projects_links_within'] = [ + 'name' => 'A listing of project links, followed by "within"', 'description' => 'The link to the related projects if published, and the site title if no projects are related.', ]; $info['tokens']['node']['primary_contact_links'] = [ @@ -249,7 +249,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $replacements[$original] = wri_common_link_or_text($data['node']); break; - case 'projects_links': + case 'projects_links_within': if ($node->hasField('field_projects') && ($projects = $node->get('field_projects')->referencedEntities())) { $replacements[$original] = _wri_common_format_list($projects); } diff --git a/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml b/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml index 1990b81b6..ca76ceb92 100644 --- a/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml +++ b/modules/wri_data/config/install/field.field.node.data.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: data label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:projects_links_within] our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' required: false translatable: true default_value: - - value: "

This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" + value: "

This [node:field_type:entity] is part of the [node:projects_links_within] our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" format: basic_html default_value_callback: '' settings: { } diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index 41fa21015..4786b82e9 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -115,10 +115,10 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { // Replace link strings with new values. $taxonomy_value[0]['value'] = str_replace( ['[node:field_primary_contacts:entity:link]', - '[node:field_projects:entity:link]', + '[node:field_projects:entity:link] within', ], ['[node:primary_contact_links]', - '[node:projects_links]', + '[node:projects_links_within]', ], $taxonomy_value[0]['value'] ); diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index d5d12f1bb..d8872fedc 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -98,11 +98,11 @@ function wri_node_update_10002() { $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ 'node:field_primary_contacts:entity:link', - 'node:field_projects:entity:link', + '[node:field_projects:entity:link] within', ]; $new_values = [ 'node:primary_contact_links', - 'node:projects_links', + '[node:projects_links_within]', ]; // Loop through the fields. diff --git a/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml b/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml index 8fe024d61..6f557abe7 100644 --- a/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml +++ b/modules/wri_publication/config/install/field.field.node.publication.field_narrative_taxonomy.yml @@ -16,12 +16,12 @@ field_name: field_narrative_taxonomy entity_type: node bundle: publication label: 'Narrative Taxonomy' -description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' +description: 'If you want to use the default value, choose "Source" and paste: <p>This [node:field_type:entity] is part of the [node:projects_links_within] our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.</p>' required: false translatable: true default_value: - - value: "

This [node:field_type:entity] is part of the [node:projects_links] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" + value: "

This [node:field_type:entity] is part of the [node:projects_links_within] within our [wri_tokens:topic_and_sub_topic_links_list]. Reach out to [node:primary_contact_links] for more information.

\r\n" format: basic_html default_value_callback: '' settings: { } From b04b63895961c93cac1c1cf90c952979efdf15c9 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Mon, 17 Jun 2024 13:20:12 -0700 Subject: [PATCH 29/48] Issue #12 adding the within phase. --- modules/wri_node/wri_node.install | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index d8872fedc..8e4ece6c0 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -119,3 +119,51 @@ function wri_node_update_10002() { $field->save(); } } + +function wri_node_update_10003() { + $collections = \Drupal::service('config.manager')->getConfigCollectionInfo(); + + foreach ($collections->getCollectionNames() as $collection_name) { + if ($collection_name) { + [, $language] = explode('.', $collection_name); + } + else { + $config_translation = \Drupal::configFactory()->getEditable('wri_node.settings'); + $language = $default_language = $config_translation->get('langcode'); + } + $phrase = 'and'; + + switch ($language) { + case 'en': + $phrase = 'and'; + break; + + case 'fr': + $phrase = 'et'; + break; + + case 'es': + $phrase = 'y'; + break; + + case 'zh-hans': + $phrase = '和'; + break; + + case 'id': + $phrase = 'dan'; + break; + + case 'pt-br': + $phrase = 'e'; + break; + } + + if ($collection_name && $default_language != $language) { + \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings')->set('within_phrase', $phrase)->save(); + } + else { + \Drupal::configFactory()->getEditable('wri_node.settings')->set('within_phrase', $phrase)->save(); + } + } +} From f41273b7f7a78f8a6de4c029ed16647f2cf795fd Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Mon, 17 Jun 2024 13:27:59 -0700 Subject: [PATCH 30/48] Issue #12 using config validation. --- .../config/schema/wri_node.schema.yml | 4 ++ modules/wri_node/src/Form/SettingsForm.php | 38 +++++++------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/modules/wri_node/config/schema/wri_node.schema.yml b/modules/wri_node/config/schema/wri_node.schema.yml index dafef6ae3..77d982c1a 100644 --- a/modules/wri_node/config/schema/wri_node.schema.yml +++ b/modules/wri_node/config/schema/wri_node.schema.yml @@ -23,3 +23,7 @@ wri_node.settings: and_phrase: type: text label: 'And word for listings, ie: 1, 2 "and" 3' + within_phrase: + type: text + label: 'And word for "within" in the phrase "is part of X-project within Y-topic"' + diff --git a/modules/wri_node/src/Form/SettingsForm.php b/modules/wri_node/src/Form/SettingsForm.php index db7e3a205..7caedd0e4 100644 --- a/modules/wri_node/src/Form/SettingsForm.php +++ b/modules/wri_node/src/Form/SettingsForm.php @@ -63,28 +63,35 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['use_fallback_image'] = [ '#type' => 'checkbox', '#title' => $this->t('Use a fallback image?'), + '#config_target' => 'wri_node.settings:use_fallback_image', '#description' => $this->t('If checked, a Card for a Node with no existing Main Image will display a default image (based on the title of the Primary topic). If one is not found the default image at default.jpg will be used.', ['@href' => $url]), - '#default_value' => $this->config('wri_node.settings')->get('use_fallback_image'), ]; $form['unpublished_person_phrase'] = [ '#type' => 'textfield', '#title' => $this->t('Unpublished Person phrase'), - '#default_value' => $this->config('wri_node.settings')->get('unpublished_person_phrase'), + '#config_target' => 'wri_node.settings:unpublished_person_phrase', '#required' => TRUE, ]; $form['and_phrase'] = [ '#type' => 'textfield', '#title' => $this->t('And word for listings, ie: 1, 2 "and" 3'), - '#default_value' => $this->config('wri_node.settings')->get('and_phrase'), + '#config_target' => 'wri_node.settings:and_phrase', + '#required' => TRUE, + ]; + + $form['within_phrase'] = [ + '#type' => 'textfield', + '#title' => $this->t('And word for "within" in the phrase "is part of X-project within Y-topic"'), + '#config_target' => 'wri_node.settings:within_phrase', '#required' => TRUE, ]; $form['person_listing_url'] = [ '#type' => 'textfield', '#title' => $this->t('Person listing url'), - '#default_value' => $this->config('wri_node.settings')->get('person_listing_url'), + '#config_target' => 'wri_node.settings:person_listing_url', '#size' => 40, '#description' => $this->t('If a narrative taxonomy contains a person link that has been unpublished, link to this url instead.'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), @@ -93,42 +100,25 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['disable_ads_data_redaction'] = [ '#type' => 'checkbox', '#title' => $this->t('Disable google consent mode?'), + '#config_target' => 'wri_node.settings:disable_ads_data_redaction', '#description' => $this->t('If checked, the tag for "ads_data_redaction" will be disabled'), - '#default_value' => $this->config('wri_node.settings')->get('disable_ads_data_redaction'), ]; $form['disable_osano_script'] = [ '#type' => 'checkbox', '#title' => $this->t('Disable Osano script from loading in Head?'), + '#config_target' => 'wri_node.settings:disable_osano_script', '#description' => $this->t('If checked, the tag for "osano_script" will be disabled'), - '#default_value' => $this->config('wri_node.settings')->get('disable_osano_script'), ]; $form['twitter_share_suffix'] = [ '#type' => 'textfield', '#title' => $this->t('Twitter Share suffix'), - '#default_value' => $this->config('wri_node.settings')->get('twitter_share_suffix'), + '#config_target' => 'wri_node.settings:twitter_share_suffix', '#size' => 40, '#description' => $this->t('On social share dropdown, the text to come after the title of a page in a tweet. Defaults to "via @WorldResources"'), ]; return parent::buildForm($form, $form_state); } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->config('wri_node.settings') - ->set('use_fallback_image', $form_state->getValue('use_fallback_image')) - ->set('unpublished_person_phrase', $form_state->getValue('unpublished_person_phrase')) - ->set('person_listing_url', $form_state->getValue('person_listing_url')) - ->set('and_phrase', $form_state->getValue('and_phrase')) - ->set('disable_ads_data_redaction', $form_state->getValue('disable_ads_data_redaction')) - ->set('disable_osano_script', $form_state->getValue('disable_osano_script')) - ->set('twitter_share_suffix', $form_state->getValue('twitter_share_suffix')) - ->save(); - parent::submitForm($form, $form_state); - } - } From 757f9c9dcf21253e04d802b545019d75a397573b Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Mon, 17 Jun 2024 13:58:19 -0700 Subject: [PATCH 31/48] Issue #12 adding logic to get a token within a setting phase. --- modules/wri_common/wri_common.module | 16 +++++-- modules/wri_node/wri_node.install | 67 +++++++--------------------- 2 files changed, 30 insertions(+), 53 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 4735bf62f..570de73c9 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -157,6 +157,10 @@ function wri_common_token_info() { 'name' => 'A node link', 'description' => 'The link to the node, if published, or its title if not.', ]; + $info['tokens']['node']['projects_links'] = [ + 'name' => 'A listing of project links', + 'description' => 'The link to the related projects if published, and nothing if not.', + ]; $info['tokens']['node']['projects_links_within'] = [ 'name' => 'A listing of project links, followed by "within"', 'description' => 'The link to the related projects if published, and the site title if no projects are related.', @@ -249,12 +253,18 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $replacements[$original] = wri_common_link_or_text($data['node']); break; - case 'projects_links_within': + case 'projects_links': if ($node->hasField('field_projects') && ($projects = $node->get('field_projects')->referencedEntities())) { $replacements[$original] = _wri_common_format_list($projects); } - else { - $replacements[$original] = \Drupal::config('system.site')->get('name'); + break; + + case 'projects_links_within': + // Get the projects_links value using tokens. + $phrase = \Drupal::config('wri_node.settings')->get('within_phrase'); + $replaced = \Drupal::token()->replace('[node:projects_links_within]', ['node' => $node], ['clear' => TRUE]); + if ($replaced) { + $replacements[$original] = \Drupal::token()->replace($phrase, ['node' => $node], ['clear' => TRUE]); } break; diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 8e4ece6c0..de8b392ad 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -54,38 +54,47 @@ function wri_node_update_10001() { $language = $default_language = $config_translation->get('langcode'); } $phrase = 'and'; + $within = 'within'; switch ($language) { case 'en': $phrase = 'and'; + $within = '[node:projects_links_within] within'; break; case 'fr': $phrase = 'et'; + $within = '[node:projects_links_within] dans'; break; case 'es': $phrase = 'y'; + $within = '[node:projects_links_within] del'; break; case 'zh-hans': - $phrase = '和'; + $within = '[node:projects_links_within] within'; + $phrase = 'and'; break; case 'id': $phrase = 'dan'; + $within = '[node:projects_links_within] dalam'; break; case 'pt-br': $phrase = 'e'; + $within = 'do projeto [node:field_projects:entity:link]'; break; } if ($collection_name && $default_language != $language) { \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings')->set('and_phrase', $phrase)->save(); + \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings')->set('within_phrase', $within)->save(); } else { \Drupal::configFactory()->getEditable('wri_node.settings')->set('and_phrase', $phrase)->save(); + \Drupal::configFactory()->getEditable('wri_node.settings')->set('within_phrase', $within)->save(); } } } @@ -98,11 +107,17 @@ function wri_node_update_10002() { $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ 'node:field_primary_contacts:entity:link', - '[node:field_projects:entity:link] within', + '[node:field_projects:entity:link] within', // en + '[node:field_projects:entity:link] dalam', // id + '[node:field_projects:entity:link] del', // es + 'do projeto [node:field_projects:entity:link]', // pt-br ]; $new_values = [ 'node:primary_contact_links', '[node:projects_links_within]', + '[node:projects_links_within]', + '[node:projects_links_within]', + '[node:projects_links_within]', ]; // Loop through the fields. @@ -119,51 +134,3 @@ function wri_node_update_10002() { $field->save(); } } - -function wri_node_update_10003() { - $collections = \Drupal::service('config.manager')->getConfigCollectionInfo(); - - foreach ($collections->getCollectionNames() as $collection_name) { - if ($collection_name) { - [, $language] = explode('.', $collection_name); - } - else { - $config_translation = \Drupal::configFactory()->getEditable('wri_node.settings'); - $language = $default_language = $config_translation->get('langcode'); - } - $phrase = 'and'; - - switch ($language) { - case 'en': - $phrase = 'and'; - break; - - case 'fr': - $phrase = 'et'; - break; - - case 'es': - $phrase = 'y'; - break; - - case 'zh-hans': - $phrase = '和'; - break; - - case 'id': - $phrase = 'dan'; - break; - - case 'pt-br': - $phrase = 'e'; - break; - } - - if ($collection_name && $default_language != $language) { - \Drupal::languageManager()->getLanguageConfigOverride($language, 'wri_node.settings')->set('within_phrase', $phrase)->save(); - } - else { - \Drupal::configFactory()->getEditable('wri_node.settings')->set('within_phrase', $phrase)->save(); - } - } -} From 553f01358ffb4e9fb751ade5b0daf079fea6e279 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Mon, 17 Jun 2024 13:58:34 -0700 Subject: [PATCH 32/48] Issue #12 No Oxford comma. --- modules/wri_common/wri_common.module | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 570de73c9..e31dfbbcd 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -388,10 +388,8 @@ function _wri_common_format_list(array $terms) { // If there is more than 1 term, build a list. if (count($terms) > 1) { if (!next($terms)) { - if (count($terms) == 2) { - // Put no comma between A and B. - $list = trim($list, ', ') . ' '; - } + // Put no comma between A and B, remove Oxford comma. + $list = trim($list, ', ') . ' '; // Leave the Oxford comma, A, B, and C. $list .= \Drupal::config('wri_node.settings')->get('and_phrase') . " $term_name"; } From da96132a37e22cd557cac8df8a8db962c3dec07e Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Mon, 17 Jun 2024 14:14:09 -0700 Subject: [PATCH 33/48] Issue #12 updating update hooks. --- modules/wri_common/wri_common.module | 2 +- .../wri_narrative.post_update.php | 2 +- modules/wri_node/wri_node.install | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index e31dfbbcd..fc6ba3eb1 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -264,7 +264,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $phrase = \Drupal::config('wri_node.settings')->get('within_phrase'); $replaced = \Drupal::token()->replace('[node:projects_links_within]', ['node' => $node], ['clear' => TRUE]); if ($replaced) { - $replacements[$original] = \Drupal::token()->replace($phrase, ['node' => $node], ['clear' => TRUE]); + $replacements[$original] = \Drupal::token()->replace($phrase, ['node' => $node], ['clear' => TRUE]) . ' '; } break; diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index 4786b82e9..6970fe1b3 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -115,7 +115,7 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { // Replace link strings with new values. $taxonomy_value[0]['value'] = str_replace( ['[node:field_primary_contacts:entity:link]', - '[node:field_projects:entity:link] within', + '[node:field_projects:entity:link] within ', ], ['[node:primary_contact_links]', '[node:projects_links_within]', diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index de8b392ad..0e4d32a15 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -40,7 +40,7 @@ function wri_node_update_9503() { } /** - * Updates the node and_phrase values. + * Updates the node and_phrase and within_phase values. */ function wri_node_update_10001() { $collections = \Drupal::service('config.manager')->getConfigCollectionInfo(); @@ -107,16 +107,24 @@ function wri_node_update_10002() { $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ 'node:field_primary_contacts:entity:link', - '[node:field_projects:entity:link] within', // en - '[node:field_projects:entity:link] dalam', // id - '[node:field_projects:entity:link] del', // es - 'do projeto [node:field_projects:entity:link]', // pt-br + '[node:field_projects:entity:link][ within ', + '[node:field_projects:entity:link] within ', // en + '[node:field_projects:entity:link][ dalam ', + '[node:field_projects:entity:link] dalam ', // id + '[node:field_projects:entity:link][ del ', + '[node:field_projects:entity:link] del ', // es + 'do projeto [node:field_projects:entity:link][ ', + 'do projeto [node:field_projects:entity:link] ', // pt-br ]; $new_values = [ 'node:primary_contact_links', + '[node:projects_links_within][', '[node:projects_links_within]', + '[node:projects_links_within][', '[node:projects_links_within]', + '[node:projects_links_within][', '[node:projects_links_within]', + '[node:projects_links_within][', '[node:projects_links_within]', ]; From 98087b7e47dcebbb8c36784904897d888a66f2cb Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Tue, 18 Jun 2024 10:14:44 -0700 Subject: [PATCH 34/48] Issue #12 accidental open paren in the example text. --- modules/wri_node/wri_node.install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 0e4d32a15..02d73f1bc 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -107,13 +107,13 @@ function wri_node_update_10002() { $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ 'node:field_primary_contacts:entity:link', - '[node:field_projects:entity:link][ within ', + '[node:field_projects:entity:link]; within ', '[node:field_projects:entity:link] within ', // en - '[node:field_projects:entity:link][ dalam ', + '[node:field_projects:entity:link] dalam ', '[node:field_projects:entity:link] dalam ', // id - '[node:field_projects:entity:link][ del ', + '[node:field_projects:entity:link] del ', '[node:field_projects:entity:link] del ', // es - 'do projeto [node:field_projects:entity:link][ ', + 'do projeto [node:field_projects:entity:link] ', 'do projeto [node:field_projects:entity:link] ', // pt-br ]; $new_values = [ From d1ca289e7c9093780587b63971c8b0abe58bc1e2 Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Tue, 18 Jun 2024 12:56:28 -0700 Subject: [PATCH 35/48] Issue #12 fixing update hook. --- modules/wri_node/wri_node.install | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 02d73f1bc..443ca33bc 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -107,7 +107,7 @@ function wri_node_update_10002() { $narrative_fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_name' => 'field_narrative_taxonomy']); $old_values = [ 'node:field_primary_contacts:entity:link', - '[node:field_projects:entity:link]; within ', + '[node:field_projects:entity:link] within ', '[node:field_projects:entity:link] within ', // en '[node:field_projects:entity:link] dalam ', '[node:field_projects:entity:link] dalam ', // id @@ -118,13 +118,13 @@ function wri_node_update_10002() { ]; $new_values = [ 'node:primary_contact_links', - '[node:projects_links_within][', + '[node:projects_links_within]', '[node:projects_links_within]', - '[node:projects_links_within][', + '[node:projects_links_within]', '[node:projects_links_within]', - '[node:projects_links_within][', + '[node:projects_links_within]', '[node:projects_links_within]', - '[node:projects_links_within][', + '[node:projects_links_within]', '[node:projects_links_within]', ]; From 2d33463fe06d75f89e6e913d0025b2d9e0d000ea Mon Sep 17 00:00:00 2001 From: Maria Fisher Date: Tue, 18 Jun 2024 13:37:59 -0700 Subject: [PATCH 36/48] Issue #12 we need to pass the string to the translation function to create the correct markup and probably to actually translate it. --- modules/wri_common/wri_common.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index fc6ba3eb1..a2f52c8b3 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -262,9 +262,9 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'projects_links_within': // Get the projects_links value using tokens. $phrase = \Drupal::config('wri_node.settings')->get('within_phrase'); - $replaced = \Drupal::token()->replace('[node:projects_links_within]', ['node' => $node], ['clear' => TRUE]); + $replaced = \Drupal::token()->replace('[node:projects_links]', ['node' => $node], ['clear' => TRUE]); if ($replaced) { - $replacements[$original] = \Drupal::token()->replace($phrase, ['node' => $node], ['clear' => TRUE]) . ' '; + $replacements[$original] = t(str_replace('[node:projects_links]', $replaced, $phrase) . ' '); } break; From 3a0144b502df678dd602bc0db0540f281428d681 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Wed, 17 Jul 2024 16:12:27 -0700 Subject: [PATCH 37/48] Issue #12 removing duplicate tags if they're in both the Topic and the Tags fields. --- modules/wri_common/wri_common.module | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index a2f52c8b3..8767d3a55 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -313,16 +313,20 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab */ function wri_common_get_node_topics(Node $node, $secondary_only = FALSE) { $topics = []; + $existing_topics = []; if (!$secondary_only && $node->hasField('field_primary_topic') && ($topic_items = $node->get('field_primary_topic')) && !$topic_items->isEmpty() && $topic_items->first()->entity) { $topics[] = $topic_items->first()->entity; + $existing_topics[$topic_items->first()->entity->id()] = TRUE; } if ($node->hasField('field_tags') && ($tag_items = $node->get('field_tags')) && !$tag_items->isEmpty()) { foreach ($tag_items as $tag_item) { - if (isset($tag_item->entity) && $tag_item->entity->bundle() == 'topics_and_subtopics' && $tag_item->entity->isPublished()) { + if (!isset($existing_topics[$tag_item->entity->id()]) && isset($tag_item->entity) && $tag_item->entity->bundle() == 'topics_and_subtopics' && $tag_item->entity->isPublished()) { $topics[] = $tag_item->entity; + $existing_topics[$tag_item->entity->id()] = TRUE; } } } + return $topics; } From 6c81404ed15e9fecc66ba3ac11e6938996ac6518 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Mon, 29 Jul 2024 13:42:55 -0700 Subject: [PATCH 38/48] Not checking for the existing topic until we know the entity id exists. --- modules/wri_common/wri_common.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 8767d3a55..908c1eb8c 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -320,7 +320,7 @@ function wri_common_get_node_topics(Node $node, $secondary_only = FALSE) { } if ($node->hasField('field_tags') && ($tag_items = $node->get('field_tags')) && !$tag_items->isEmpty()) { foreach ($tag_items as $tag_item) { - if (!isset($existing_topics[$tag_item->entity->id()]) && isset($tag_item->entity) && $tag_item->entity->bundle() == 'topics_and_subtopics' && $tag_item->entity->isPublished()) { + if (isset($tag_item->entity) && $tag_item->entity->bundle() == 'topics_and_subtopics' && $tag_item->entity->isPublished() && !isset($existing_topics[$tag_item->entity->id()]) ) { $topics[] = $tag_item->entity; $existing_topics[$tag_item->entity->id()] = TRUE; } From bef530fbe21116ae0de5735de157f28347f696c2 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Mon, 29 Jul 2024 14:14:24 -0700 Subject: [PATCH 39/48] Json feed items can't get the node type by page url. #12. --- modules/wri_common/wri_common.module | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 908c1eb8c..6484daeb2 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -272,7 +272,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab if ($node->hasField('field_primary_contacts') && ($contact_items = $node->get('field_primary_contacts')) && !$contact_items->isEmpty()) { $contact_item = $contact_items->first()->entity; if ($contact_item) { - $replacements[$original] = wri_common_link_or_text($contact_item); + $replacements[$original] = wri_common_link_or_text($contact_item, $node); } else { $replacements[$original] = wri_common_person_link_fallback($node); @@ -416,20 +416,20 @@ function _wri_common_format_list(array $terms) { * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. + * @param \Drupal\node\Entity\NodeInterface $node + * The node that this entity is appearing on, if not the same as the entity. * * @return string * A string representing the entity with or without a link. */ -function wri_common_link_or_text(EntityInterface $entity) { +function wri_common_link_or_text(EntityInterface $entity, NodeInterface $node = NULL) { $link = ''; if (isset($entity)) { if ($entity->isPublished()) { $link = $entity->toLink()->toString(); } else { - if ($entity->bundle() == 'person') { - // See if the current page is a node. - $node = \Drupal::routeMatch()->getParameter('node'); + if ($entity->bundle() == 'person' && $node) { $link = wri_common_person_link_fallback($node); } else { From a0d2cf13db4acd2e0771a0c0635d28b3e44b905b Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Mon, 29 Jul 2024 14:18:58 -0700 Subject: [PATCH 40/48] Removing t string which didn't help us. --- modules/wri_common/wri_common.module | 4 ++-- modules/wri_node/src/Form/SettingsForm.php | 1 + modules/wri_node/wri_node.install | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 6484daeb2..6da38457c 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -264,7 +264,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $phrase = \Drupal::config('wri_node.settings')->get('within_phrase'); $replaced = \Drupal::token()->replace('[node:projects_links]', ['node' => $node], ['clear' => TRUE]); if ($replaced) { - $replacements[$original] = t(str_replace('[node:projects_links]', $replaced, $phrase) . ' '); + $replacements[$original] = str_replace('[node:projects_links]', $replaced, $phrase) . ' '; } break; @@ -320,7 +320,7 @@ function wri_common_get_node_topics(Node $node, $secondary_only = FALSE) { } if ($node->hasField('field_tags') && ($tag_items = $node->get('field_tags')) && !$tag_items->isEmpty()) { foreach ($tag_items as $tag_item) { - if (isset($tag_item->entity) && $tag_item->entity->bundle() == 'topics_and_subtopics' && $tag_item->entity->isPublished() && !isset($existing_topics[$tag_item->entity->id()]) ) { + if (isset($tag_item->entity) && $tag_item->entity->bundle() == 'topics_and_subtopics' && $tag_item->entity->isPublished() && !isset($existing_topics[$tag_item->entity->id()])) { $topics[] = $tag_item->entity; $existing_topics[$tag_item->entity->id()] = TRUE; } diff --git a/modules/wri_node/src/Form/SettingsForm.php b/modules/wri_node/src/Form/SettingsForm.php index 7caedd0e4..aa20217af 100644 --- a/modules/wri_node/src/Form/SettingsForm.php +++ b/modules/wri_node/src/Form/SettingsForm.php @@ -121,4 +121,5 @@ public function buildForm(array $form, FormStateInterface $form_state) { return parent::buildForm($form, $form_state); } + } diff --git a/modules/wri_node/wri_node.install b/modules/wri_node/wri_node.install index 443ca33bc..0c0d72b26 100644 --- a/modules/wri_node/wri_node.install +++ b/modules/wri_node/wri_node.install @@ -108,13 +108,17 @@ function wri_node_update_10002() { $old_values = [ 'node:field_primary_contacts:entity:link', '[node:field_projects:entity:link] within ', - '[node:field_projects:entity:link] within ', // en + // En. + '[node:field_projects:entity:link] within ', '[node:field_projects:entity:link] dalam ', - '[node:field_projects:entity:link] dalam ', // id + // Id. + '[node:field_projects:entity:link] dalam ', '[node:field_projects:entity:link] del ', - '[node:field_projects:entity:link] del ', // es + // Es. + '[node:field_projects:entity:link] del ', 'do projeto [node:field_projects:entity:link] ', - 'do projeto [node:field_projects:entity:link] ', // pt-br + // pt-br. + 'do projeto [node:field_projects:entity:link] ', ]; $new_values = [ 'node:primary_contact_links', From 63f3a79af97544a5321d92a753df30238bd36eb4 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Tue, 30 Jul 2024 11:41:52 -0700 Subject: [PATCH 41/48] Fixing Translation to work with phpcs. --- modules/wri_common/wri_common.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 6da38457c..d6d8309cb 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -264,7 +264,7 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab $phrase = \Drupal::config('wri_node.settings')->get('within_phrase'); $replaced = \Drupal::token()->replace('[node:projects_links]', ['node' => $node], ['clear' => TRUE]); if ($replaced) { - $replacements[$original] = str_replace('[node:projects_links]', $replaced, $phrase) . ' '; + $replacements[$original] = Markup::create((str_replace('[node:projects_links_within]', $replaced, $phrase) . ' ')); } break; From 5493ea0d8f66064ac7962c4fc6d6372949f2144d Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Wed, 31 Jul 2024 14:46:08 -0700 Subject: [PATCH 42/48] Cleaning old data. --- modules/wri_narrative/wri_narrative.post_update.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/wri_narrative/wri_narrative.post_update.php b/modules/wri_narrative/wri_narrative.post_update.php index 6970fe1b3..687d8df7e 100644 --- a/modules/wri_narrative/wri_narrative.post_update.php +++ b/modules/wri_narrative/wri_narrative.post_update.php @@ -75,7 +75,12 @@ function wri_narrative_post_update_rewrite_narrative_taxonomies(&$sandbox) { /** * Updates the tokens in narrative taxonomies, round 2. */ -function wri_narrative_post_update_rewrite_narrative_taxonomies2(&$sandbox) { +function wri_narrative_post_update_rewrite_narrative_taxonomies3(&$sandbox) { + // We don't display the narrative taxonomy on nodes older than 2020, so clear + // that boilerplate out of the database. + Drupal::database()->query("DELETE FROM node__field_narrative_taxonomy WHERE entity_id IN (SELECT nid FROM node_field_data WHERE created<1577836800 AND type IN ('data', 'publication'))")->execute(); + Drupal::database()->query("DELETE FROM node_revision__field_narrative_taxonomy WHERE entity_id IN (SELECT nid FROM node_field_data WHERE created<1577836800 AND type IN ('data', 'publication'))")->execute(); + if (!isset($sandbox['total'])) { $sandbox['total'] = Drupal::database()->select('node__field_narrative_taxonomy', 'u') ->condition('u.field_narrative_taxonomy_value', '[node:field_(projects|primary_contacts):entity:link]', 'REGEXP') From b1001f73f13ad75cbdbee0f1129e630083d17c1f Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Wed, 31 Jul 2024 15:27:11 -0700 Subject: [PATCH 43/48] Issue #12 only showing published projects. --- modules/wri_common/wri_common.module | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index d6d8309cb..9665680b1 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -255,7 +255,14 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'projects_links': if ($node->hasField('field_projects') && ($projects = $node->get('field_projects')->referencedEntities())) { - $replacements[$original] = _wri_common_format_list($projects); + $published_projects = []; + foreach ($projects as $project) { + if ($project->isPublished()) { + $published_projects[] = $project; + } + } + + $replacements[$original] = _wri_common_format_list($published_projects); } break; From 129094f8efc538f7225560156f754739f9149a23 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Thu, 22 Aug 2024 11:54:13 -0700 Subject: [PATCH 44/48] Issue #12 filtering out topics whose landing page would match the Projects field value. --- modules/wri_common/wri_common.module | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 9665680b1..647e58487 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -223,6 +223,22 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'topic_and_sub_topic_links_list': $terms = wri_common_get_node_topics($node, FALSE); + // If the node has a topic whose Landing page points to a value in Project, + // filter that out. + if ($terms && $node->hasField('field_projects') && ($projects = $node->get('field_projects')) && !$projects->isEmpty()) { + $project_items = []; + $allowed_terms = []; + foreach ($projects->getValue() as $value) { + $project_items[] = $value['target_id']; + } + foreach ($terms as $term) { + if (!in_array($term->field_landing_page->target_id, $project_items)) { + $allowed_terms[] = $term; + } + } + $terms = $allowed_terms; + } + if (empty($terms)) { $replacements[$original] = \Drupal::config('system.site')->get('name'); } From aba370f076d66017fb381acf6e8eb3422aa30b8e Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Thu, 22 Aug 2024 12:46:15 -0700 Subject: [PATCH 45/48] Issue #12 updating the project expert link to work on the multidev instead of on Flagship. --- modules/wri_common/wri_common.module | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 647e58487..8c5bb1b45 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -474,11 +474,14 @@ function wri_common_link_or_text(EntityInterface $entity, NodeInterface $node = */ function wri_common_person_link_fallback(EntityInterface $node) { $url = Url::fromUserInput(\Drupal::config('wri_node.settings')->get('person_listing_url')); + $prefix = $suffix = ''; if ($node instanceof NodeInterface) { // If the current page is a project, link to its experts page. if ($node->bundle() == 'project_detail') { $url = Url::fromUserInput('/project-experts/' . $node->id()); + $prefix = ''; + $suffix = ''; } // Otherwise, see if that node has a 'field_projects', and THAT node // is published. @@ -487,12 +490,15 @@ function wri_common_person_link_fallback(EntityInterface $node) { if ($project && $project->isPublished()) { // If it is, link to the projects/experts page. $url = Url::fromUserInput('/project-experts/' . $node->field_projects->target_id); + $prefix = ''; + $suffix = ''; } } } // Fallback to the /about/experts page. $link = Link::fromTextAndUrl(\Drupal::config('wri_node.settings')->get('unpublished_person_phrase'), $url)->toString(); + $link->setGeneratedLink($prefix . $link . $suffix); return $link; } From 86b0a5466d1b35b97c35bcb23b0e572db9a0bc11 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Thu, 22 Aug 2024 13:13:13 -0700 Subject: [PATCH 46/48] Issue #12 turning the comment into a span tag, which will not get stripped by the filter. --- modules/wri_common/wri_common.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 8c5bb1b45..112c962a2 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -480,8 +480,8 @@ function wri_common_person_link_fallback(EntityInterface $node) { // If the current page is a project, link to its experts page. if ($node->bundle() == 'project_detail') { $url = Url::fromUserInput('/project-experts/' . $node->id()); - $prefix = ''; - $suffix = ''; + $prefix = ''; + $suffix = ''; } // Otherwise, see if that node has a 'field_projects', and THAT node // is published. @@ -490,8 +490,8 @@ function wri_common_person_link_fallback(EntityInterface $node) { if ($project && $project->isPublished()) { // If it is, link to the projects/experts page. $url = Url::fromUserInput('/project-experts/' . $node->field_projects->target_id); - $prefix = ''; - $suffix = ''; + $prefix = ''; + $suffix = ''; } } } From 439ec8f141e41b69cc25a3271b45a26aacaaef32 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Thu, 22 Aug 2024 15:28:28 -0700 Subject: [PATCH 47/48] Issue #12 refactoring the project experts links so I can check against it on africa. --- modules/wri_common/wri_common.module | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 112c962a2..3ec65224d 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -473,15 +473,25 @@ function wri_common_link_or_text(EntityInterface $entity, NodeInterface $node = * The link. */ function wri_common_person_link_fallback(EntityInterface $node) { - $url = Url::fromUserInput(\Drupal::config('wri_node.settings')->get('person_listing_url')); - $prefix = $suffix = ''; + $url = wri_common_url_from_node_project($node); + if (!$url) { + $url = Url::fromUserInput(\Drupal::config('wri_node.settings') + ->get('person_listing_url')); + } + + // Fallback to the /about/experts page. + $link = Link::fromTextAndUrl(\Drupal::config('wri_node.settings')->get('unpublished_person_phrase'), $url)->toString(); + $link->setGeneratedLink($link); + + return $link; +} + +function wri_common_url_from_node_project($node) { if ($node instanceof NodeInterface) { // If the current page is a project, link to its experts page. if ($node->bundle() == 'project_detail') { $url = Url::fromUserInput('/project-experts/' . $node->id()); - $prefix = ''; - $suffix = ''; } // Otherwise, see if that node has a 'field_projects', and THAT node // is published. @@ -490,17 +500,10 @@ function wri_common_person_link_fallback(EntityInterface $node) { if ($project && $project->isPublished()) { // If it is, link to the projects/experts page. $url = Url::fromUserInput('/project-experts/' . $node->field_projects->target_id); - $prefix = ''; - $suffix = ''; } } } - - // Fallback to the /about/experts page. - $link = Link::fromTextAndUrl(\Drupal::config('wri_node.settings')->get('unpublished_person_phrase'), $url)->toString(); - $link->setGeneratedLink($prefix . $link . $suffix); - - return $link; + return FALSE; } /** From 32b105ace1c0c7261b9df5a1189e762194ab0c91 Mon Sep 17 00:00:00 2001 From: Thinkshout Automation Date: Thu, 22 Aug 2024 15:50:14 -0700 Subject: [PATCH 48/48] Issue #12 PHPCS. --- modules/wri_common/wri_common.module | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 3ec65224d..b9b02c355 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -223,8 +223,8 @@ function wri_common_tokens($type, $tokens, array $data, array $options, Bubbleab case 'topic_and_sub_topic_links_list': $terms = wri_common_get_node_topics($node, FALSE); - // If the node has a topic whose Landing page points to a value in Project, - // filter that out. + // If the node has a topic whose Landing page points to a value in + // Project, filter that out. if ($terms && $node->hasField('field_projects') && ($projects = $node->get('field_projects')) && !$projects->isEmpty()) { $project_items = []; $allowed_terms = []; @@ -482,12 +482,21 @@ function wri_common_person_link_fallback(EntityInterface $node) { // Fallback to the /about/experts page. $link = Link::fromTextAndUrl(\Drupal::config('wri_node.settings')->get('unpublished_person_phrase'), $url)->toString(); - $link->setGeneratedLink($link); return $link; } +/** + * Get the URL for a project from a node. + * + * @param \Drupal\Core\Entity\EntityInterface $node + * The node. + * + * @return \Drupal\Core\Url|false\ + * The url, or false if no url could be produced. + */ function wri_common_url_from_node_project($node) { + $url = FALSE; if ($node instanceof NodeInterface) { // If the current page is a project, link to its experts page. if ($node->bundle() == 'project_detail') { @@ -503,7 +512,7 @@ function wri_common_url_from_node_project($node) { } } } - return FALSE; + return $url; } /**