From 96bd29b33777e6a47c9c2932d2343757b1cb3414 Mon Sep 17 00:00:00 2001 From: ekes Date: Tue, 4 Nov 2025 13:13:06 +0100 Subject: [PATCH] Fix/2.x/335 path alias (#337) * Fixes prefixes (subdirectory, language) being included in parent path pattern. See https://github.com/localgovdrupal/localgov_services/issues/335#issuecomment-3461396195 * Fixes prefixes (subdirectory, language) being included in parent path pattern for other instances. See https://github.com/localgovdrupal/localgov_services/issues/335#issuecomment-3461396195 * Coding standards fix. --- ...to.pattern.localgov_services_hierarchy.yml | 2 +- localgov_services.post_update.php | 22 +++++++++++++++++++ .../localgov_services_navigation.module | 4 ++-- ...thauto.pattern.localgov_service_status.yml | 2 +- .../localgov_services_status.post_update.php | 22 +++++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 localgov_services.post_update.php create mode 100644 modules/localgov_services_status/localgov_services_status.post_update.php diff --git a/config/install/pathauto.pattern.localgov_services_hierarchy.yml b/config/install/pathauto.pattern.localgov_services_hierarchy.yml index 1fe2699..9235eff 100644 --- a/config/install/pathauto.pattern.localgov_services_hierarchy.yml +++ b/config/install/pathauto.pattern.localgov_services_hierarchy.yml @@ -6,7 +6,7 @@ dependencies: id: localgov_services_hierarchy label: 'Services Hierarchy' type: 'canonical_entities:node' -pattern: '[node:localgov_services_parent:entity:url:relative]/[node:title]' +pattern: '[node:localgov_services_parent:entity:url:path]/[node:title]' selection_criteria: 9dd1b1bc-3678-4642-8568-86d6d27c3dfd: id: 'entity_bundle:node' diff --git a/localgov_services.post_update.php b/localgov_services.post_update.php new file mode 100644 index 0000000..a6a6dfa --- /dev/null +++ b/localgov_services.post_update.php @@ -0,0 +1,22 @@ +getPattern() == '[node:localgov_services_parent:entity:url:relative]/[node:title]' + ) { + $alias->setPattern('[node:localgov_services_parent:entity:url:path]/[node:title]'); + $alias->save(); + } +} diff --git a/modules/localgov_services_navigation/localgov_services_navigation.module b/modules/localgov_services_navigation/localgov_services_navigation.module index cab41e2..333b8ec 100644 --- a/modules/localgov_services_navigation/localgov_services_navigation.module +++ b/modules/localgov_services_navigation/localgov_services_navigation.module @@ -65,8 +65,8 @@ function localgov_services_navigation_pathauto_pattern_alter(PathautoPattern $pa // it has opt-ed in with the field add the (optional) parent to the path. $entity = reset($context['data']); assert($entity instanceof ContentEntityInterface); - if ($entity->hasField('localgov_services_parent') && strpos($pattern->getPattern(), '[node:localgov_services_parent:entity:url:relative]') === FALSE) { - $pattern->setPattern('[node:localgov_services_parent:entity:url:relative]/' . $pattern->getPattern()); + if ($entity->hasField('localgov_services_parent') && strpos($pattern->getPattern(), '[node:localgov_services_parent:entity:url:path]') === FALSE) { + $pattern->setPattern('[node:localgov_services_parent:entity:url:path]/' . $pattern->getPattern()); } } diff --git a/modules/localgov_services_status/config/optional/pathauto.pattern.localgov_service_status.yml b/modules/localgov_services_status/config/optional/pathauto.pattern.localgov_service_status.yml index 8b09ea6..fc624e6 100644 --- a/modules/localgov_services_status/config/optional/pathauto.pattern.localgov_service_status.yml +++ b/modules/localgov_services_status/config/optional/pathauto.pattern.localgov_service_status.yml @@ -6,7 +6,7 @@ dependencies: id: localgov_service_status label: 'Service Status Page' type: 'canonical_entities:node' -pattern: '[node:localgov_services_parent:entity:url:relative]/status/[node:title]' +pattern: '[node:localgov_services_parent:entity:url:path]/status/[node:title]' selection_criteria: fb899c5a-41f3-4482-9b7d-7f203c4290c4: id: 'entity_bundle:node' diff --git a/modules/localgov_services_status/localgov_services_status.post_update.php b/modules/localgov_services_status/localgov_services_status.post_update.php new file mode 100644 index 0000000..83b32c1 --- /dev/null +++ b/modules/localgov_services_status/localgov_services_status.post_update.php @@ -0,0 +1,22 @@ +getPattern() == '[node:localgov_services_parent:entity:url:relative]/status/[node:title]' + ) { + $alias->setPattern('[node:localgov_services_parent:entity:url:path]/status/[node:title]'); + $alias->save(); + } +}