diff --git a/pathauto.install b/pathauto.install index 1f9f330..71c007f 100644 --- a/pathauto.install +++ b/pathauto.install @@ -221,28 +221,21 @@ function pathauto_update_8101() { * Update node type conditions from entity_bundle to node_type. */ function pathauto_update_8102() { - // Load all patterns that apply to nodes. - $pattern_ids = \Drupal::entityQuery('pathauto_pattern')->condition('type', 'canonical_entities:node')->execute(); - $pattern_entities = PathautoPattern::loadMultiple($pattern_ids); - - // Loop patterns and change the entity_bundle:node condition by a node_type - // condition, while keeping the rest of the configuration intact. - foreach ($pattern_entities as $pattern) { - foreach ($pattern->getSelectionConditions() as $condition_id => $condition) { - if ($condition->getPluginId() == 'entity_bundle:node') { - // We found the entity bundle condition. Swap it by a node type one. - $configuration = $condition->getConfiguration(); - $pattern->removeSelectionCondition($condition_id); - $pattern->addSelectionCondition([ - 'id' => 'node_type', - 'bundles' => $configuration['bundles'], - 'negate' => $configuration['negate'], - 'context_mapping' => [ - 'node' => 'node', - ], - ]); - $pattern->save(); - break; + // Load all pattern configuration entities. + foreach (\Drupal::configFactory()->listAll('pathauto.pattern.') as $pattern_config_name) { + $pattern_config = \Drupal::configFactory()->getEditable($pattern_config_name); + + // Loop patterns and swap the entity_bundle:node plugin by the node_type + // plugin. + if ($pattern_config->get('type') == 'canonical_entities:node') { + $selection_criteria = $pattern_config->get('selection_criteria'); + foreach ($selection_criteria as $uuid => $condition) { + if ($condition['id'] == 'entity_bundle:node') { + $selection_criteria[$uuid]['id'] = 'node_type'; + $pattern_config->set('selection_criteria', $selection_criteria); + $pattern_config->save(); + break; + } } } } diff --git a/src/Form/PatternEditForm.php b/src/Form/PatternEditForm.php index 6c443d9..f7abd1e 100644 --- a/src/Form/PatternEditForm.php +++ b/src/Form/PatternEditForm.php @@ -218,9 +218,7 @@ class PatternEditForm extends EntityForm { if ($bundles = array_filter((array) $form_state->getValue('bundles'))) { $default_weight -= 5; - $plugin_id = $entity_type == 'node' - ? 'node_type' - : 'entity_bundle:' . $entity_type; + $plugin_id = $entity_type == 'node' ? 'node_type' : 'entity_bundle:' . $entity_type; $entity->addSelectionCondition( [ 'id' => $plugin_id, diff --git a/src/Tests/PathautoTestHelperTrait.php b/src/Tests/PathautoTestHelperTrait.php index d0886d7..705920b 100644 --- a/src/Tests/PathautoTestHelperTrait.php +++ b/src/Tests/PathautoTestHelperTrait.php @@ -55,9 +55,11 @@ trait PathautoTestHelperTrait { * The bundle */ protected function addBundleCondition(PathautoPatternInterface $pattern, $entity_type, $bundle) { + $plugin_id = $entity_type == 'node' ? 'node_type' : 'entity_bundle:' . $entity_type; + $pattern->addSelectionCondition( [ - 'id' => 'entity_bundle:' . $entity_type, + 'id' => $plugin_id, 'bundles' => [ $bundle => $bundle, ],