Comments

huzooka created an issue. See original summary.

wim leers’s picture

+++ b/src/Plugin/migrate/process/PathautoPatternSelectionCriteria.php
@@ -30,22 +31,45 @@ class PathautoPatternSelectionCriteria extends ProcessPluginBase {
+        'context_mapping' => [
+          'language' => "$entity_type:langcode:language",
+        ],

This generates a context mapping of

'language' ⇒ 'node:langcode:language'

but when \Drupal\Core\Plugin\Context\ContextHandler::applyContextMapping() runs this code:

      try {
        $context = $plugin->getContext($context_id);
      }
      catch (ContextException $e) {
        $context = NULL;
      }
      // @todo Remove in https://www.drupal.org/project/drupal/issues/3046342.
      catch (PluginException $e) {
        $context = NULL;
      }

the first catch catches the exception:

and … silences it 😨 (This silencing was introduced by #3029625: Do not throw an exception when a context is missing while applying context mapping to a plugin if that context was previously set + #3046243: Regression: Optional context values may throw exceptions if unsatisfied.)

But then eventually in that same \Drupal\Core\Plugin\Context\ContextHandler::applyContextMapping(), a different ContextException is generated:

    if (!empty($mappings)) {
      throw new ContextException('Assigned contexts were not satisfied: ' . implode(',', array_keys($mappings)));
    }

The problem here is that the much more specific and hence helpful throw new ContextException(sprintf("The %s context is not a valid context.", $name)); exception is never actually shown; the only way to get at it is by stepping through the code with a debugger.

wim leers’s picture

The problem here is that the much more specific and hence helpful throw new ContextException(sprintf("The %s context is not a valid context.", $name)); exception is never actually shown; the only way to get at it is by stepping through the code with a debugger.

An exact Google search only finds to matches: https://www.google.com/search?hl=en&ei=OrpIYLzgLJG9sAeytI3QDA&q=%22node%... — those are #1669876: Add missing language functionality in search module and #2660236: Wrong export of context_definitions resulting in Fatal error node form.

The first search result is completely irrelevant — no clue why Google lists this as an exact match 🤷‍♂️

The second … is highly relevant.

wim leers’s picture

Status: Postponed » Needs work

Paired with @huzooka and we figured out the root cause by exporting all config, resaving the pathauto patterns from the config UI and then re-exporting:

 sites/default/config/pathauto.pattern.node_page.yml    |  3 ++-
 sites/default/config/pathauto.pattern.node_page_en.yml | 10 +++++++---
 sites/default/config/pathauto.pattern.node_page_es.yml | 10 +++++++---
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/sites/default/config/pathauto.pattern.node_page.yml b/sites/default/config/pathauto.pattern.node_page.yml
index ba4dcb1916..53bc72871b 100644
--- a/sites/default/config/pathauto.pattern.node_page.yml
+++ b/sites/default/config/pathauto.pattern.node_page.yml
@@ -9,13 +9,14 @@ label: 'Content - Pages'
 type: 'canonical_entities:node'
 pattern: '[node:menu-link:parents:join-path]/[node:title]'
 selection_criteria:
-  -
+  701f5967-eb94-4f19-8365-e0f62d62a8e7:
     id: node_type
     bundles:
       page: page
     negate: false
     context_mapping:
       node: node
+    uuid: 701f5967-eb94-4f19-8365-e0f62d62a8e7
 selection_logic: and
 weight: 0
 relationships: {  }
diff --git a/sites/default/config/pathauto.pattern.node_page_en.yml b/sites/default/config/pathauto.pattern.node_page_en.yml
index e5d9aa435a..610a2084f3 100644
--- a/sites/default/config/pathauto.pattern.node_page_en.yml
+++ b/sites/default/config/pathauto.pattern.node_page_en.yml
@@ -10,20 +10,24 @@ label: 'Content - Pages (en)'
 type: 'canonical_entities:node'
 pattern: '[node:menu-link:parents:join-path]/[node:title]'
 selection_criteria:
-  -
+  59dcb9f7-b4e0-49b6-bc7b-0d81fcb74986:
     id: node_type
     bundles:
       page: page
     negate: false
     context_mapping:
       node: node
-  -
+    uuid: 59dcb9f7-b4e0-49b6-bc7b-0d81fcb74986
+  91416cc9-0280-4f25-ac1d-72af506eb992:
     id: language
     langcodes:
       en: en
     negate: false
     context_mapping:
       language: 'node:langcode:language'
+    uuid: 91416cc9-0280-4f25-ac1d-72af506eb992
 selection_logic: and
 weight: -1
-relationships: {  }
+relationships:
+  'node:langcode:language':
+    label: Language
diff --git a/sites/default/config/pathauto.pattern.node_page_es.yml b/sites/default/config/pathauto.pattern.node_page_es.yml
index 088ddc374a..e53cf51b2c 100644
--- a/sites/default/config/pathauto.pattern.node_page_es.yml
+++ b/sites/default/config/pathauto.pattern.node_page_es.yml
@@ -10,20 +10,24 @@ label: 'Content - Pages (es)'
 type: 'canonical_entities:node'
 pattern: '[node:menu-link:parents:join-path]/[node:title]'
 selection_criteria:
-  -
+  4bca51df-9387-496d-a784-de31ec6abb61:
     id: node_type
     bundles:
       page: page
     negate: false
     context_mapping:
       node: node
-  -
+    uuid: 4bca51df-9387-496d-a784-de31ec6abb61
+  c5929f88-ba70-4047-ac1b-6b1def163c91:
     id: language
     langcodes:
       es: es
     negate: false
     context_mapping:
       language: 'node:langcode:language'
+    uuid: c5929f88-ba70-4047-ac1b-6b1def163c91
 selection_logic: and
 weight: -1
-relationships: {  }
+relationships:
+  'node:langcode:language':
+    label: Language

Obviously the absence of config entity validation is a huge risk during migrations … 😬

So we'll need to update

+++ b/src/Plugin/migrate/process/PathautoPatternSelectionCriteria.php
@@ -30,22 +31,45 @@ class PathautoPatternSelectionCriteria extends ProcessPluginBase {
+    if (is_string($langcode)) {
+      $selection_criteria[] = [
+        'id' => 'language',
+        'langcodes' => [
+          $langcode => $langcode,
+        ],
+        'negate' => FALSE,
+        'context_mapping' => [
+          'language' => "$entity_type:langcode:language",
+        ],
+      ];
+    }

… to also specify the relationships key.

wim leers’s picture

huzooka’s picture

Assigned: Unassigned » huzooka
huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review
StatusFileSize
new15.36 KB
new41.6 KB
new9.02 KB
new25.65 KB

This patch should address the issues raised in the previous comments:

  • Selection criteria configs will have a UUID.
  • Relationship config is generated (basically I had to copy a logic referenced on the Pathauto entity form to a process plugin :sad-panda-face: )..
wim leers’s picture

Status: Needs review » Postponed

Manually tested: works great! 👏🤩

huzooka’s picture

Title: Migrate language-specific patterns » [PP-2] Migrate language-specific patterns
StatusFileSize
new42.07 KB
new2 KB

Slightly updated test module... fix-only patch is the same as in #8.

huzooka’s picture

#12 ignores checking dependencies metadata calculated by the config entity class 👍.

jienckebd’s picture

The node_type condition plugin was deprecated since Drupal 9.3 in favor of a generalized entity_bundle:* condition plugin.

This pathauto issue applies this change to 1.x branch.

The patch in this issue still references the removed node_type condition plugin and results in test failures.

The attached patch replaces references to the node_type condition plugin with references to the generalized entity_bundle:node condition plugin.

jienckebd’s picture

It seems that this issue combines 4 pathauto 1.x issues including this one. So I applied the same change to that issue to make the combined patch pass tests.