From 7b8f11f02c9da6bada595a3318d7b8a48624a0b7 Mon Sep 17 00:00:00 2001 From: OscarMerida Date: Fri, 20 Dec 2024 11:15:33 -0500 Subject: [PATCH 1/4] USAGOV-2150-es-wizard-crumb: Removes the if-clause to prepend Spanish path by asking Drupal for the Breadcrumb URI in the expected language. --- .../custom/usagov_wizard/usagov_wizard.module | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/modules/custom/usagov_wizard/usagov_wizard.module b/web/modules/custom/usagov_wizard/usagov_wizard.module index 195d8532de..8d67bf477d 100644 --- a/web/modules/custom/usagov_wizard/usagov_wizard.module +++ b/web/modules/custom/usagov_wizard/usagov_wizard.module @@ -408,22 +408,22 @@ function usagov_wizard_get_term_breadcrumb(Term $rootTerm): array { if (isset($rootTerm->field_wizard_breadcrumbs)) { $crumbs = $rootTerm->field_wizard_breadcrumbs->getValue(); $result = []; + foreach ($crumbs as $crumb) { if (isset($crumb['uri'])) { - $crumb['url'] = Url::fromUri($crumb['uri'])->toString(); - // Sometimes Drupal doesn't prepend Spanish path prefix. // Sometimes this crumb's uri is "route:" and the url is an empty string; // in that case we should leave it empty (current page, not to be linked). - if ($crumb['url'] && $rootTerm->language()->getId() === 'es' && !str_starts_with($crumb['url'], '/es/')) { - $crumb['url'] = '/es' . $crumb['url']; - } + // Setting the language here assumes all the crumbs are pages from the same language + // as the root term. + $crumb['url'] = Url::fromUri($crumb['uri'], ['language' => $rootTerm->language()])->toString(); } if (isset($crumb['title'])) { - $crumb['text'] = ($crumb['title']); + $crumb['text'] = $crumb['title']; } $result[] = $crumb; } + $language = $rootTerm->langcode->value; $home = [ 'text' => $language === 'en' ? TaxonomyDatalayerBuilder::HOME_TITLE_EN : TaxonomyDatalayerBuilder::HOME_TITLE_ES, From 16a5995c7e7b87b9323bb23d6caa2f58de24a1d1 Mon Sep 17 00:00:00 2001 From: OscarMerida Date: Fri, 20 Dec 2024 15:56:43 -0500 Subject: [PATCH 2/4] USAGOV-2150-es-wizard-crumb: Remove comment per review request. --- web/modules/custom/usagov_wizard/usagov_wizard.module | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/modules/custom/usagov_wizard/usagov_wizard.module b/web/modules/custom/usagov_wizard/usagov_wizard.module index 8d67bf477d..04393869dd 100644 --- a/web/modules/custom/usagov_wizard/usagov_wizard.module +++ b/web/modules/custom/usagov_wizard/usagov_wizard.module @@ -411,8 +411,6 @@ function usagov_wizard_get_term_breadcrumb(Term $rootTerm): array { foreach ($crumbs as $crumb) { if (isset($crumb['uri'])) { - // Sometimes this crumb's uri is "route:" and the url is an empty string; - // in that case we should leave it empty (current page, not to be linked). // Setting the language here assumes all the crumbs are pages from the same language // as the root term. $crumb['url'] = Url::fromUri($crumb['uri'], ['language' => $rootTerm->language()])->toString(); From c078be2e6ce071e345fdacc48159b5caa23520dc Mon Sep 17 00:00:00 2001 From: OscarMerida Date: Thu, 26 Dec 2024 14:58:12 -0500 Subject: [PATCH 3/4] USAGOV-2150-es-wizard-crumb: Use alias path manager to get the URL with language prefix for internal paths. --- .../custom/usagov_wizard/usagov_wizard.module | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/usagov_wizard/usagov_wizard.module b/web/modules/custom/usagov_wizard/usagov_wizard.module index 04393869dd..2993a182c5 100644 --- a/web/modules/custom/usagov_wizard/usagov_wizard.module +++ b/web/modules/custom/usagov_wizard/usagov_wizard.module @@ -408,12 +408,27 @@ function usagov_wizard_get_term_breadcrumb(Term $rootTerm): array { if (isset($rootTerm->field_wizard_breadcrumbs)) { $crumbs = $rootTerm->field_wizard_breadcrumbs->getValue(); $result = []; - + $alias_manager = \Drupal::service('path_alias.manager'); foreach ($crumbs as $crumb) { if (isset($crumb['uri'])) { + + if (str_starts_with($crumb['uri'], 'internal:')) { + // We need to handle when an internal path to a Spanish page is part of + // the breadcrumb but without an /es/ prefix. + $path = preg_replace('/^internal\:/', '', $crumb['uri']); + $path = $alias_manager->getPathByAlias($path, $rootTerm->language()->getId()); + $url = Url::fromUri('internal:' . $path, ['language' => $rootTerm->language()])->toString(); + if ($url) { + $crumb['url'] = $url; + } + } + // Setting the language here assumes all the crumbs are pages from the same language // as the root term. - $crumb['url'] = Url::fromUri($crumb['uri'], ['language' => $rootTerm->language()])->toString(); + if (!isset($crumb['url'])) { + $crumb['url'] = Url::fromUri($crumb['uri'], ['language' => $rootTerm->language()]) + ->toString(); + } } if (isset($crumb['title'])) { $crumb['text'] = $crumb['title']; From f9a1c2b1c62615e0fb93ee35e7f07456105bf8a9 Mon Sep 17 00:00:00 2001 From: OscarMerida Date: Thu, 26 Dec 2024 15:19:16 -0500 Subject: [PATCH 4/4] USAGOV-2150-es-wizard-crumb: Remove linewrap --- web/modules/custom/usagov_wizard/usagov_wizard.module | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/modules/custom/usagov_wizard/usagov_wizard.module b/web/modules/custom/usagov_wizard/usagov_wizard.module index 2993a182c5..cba970754c 100644 --- a/web/modules/custom/usagov_wizard/usagov_wizard.module +++ b/web/modules/custom/usagov_wizard/usagov_wizard.module @@ -426,8 +426,7 @@ function usagov_wizard_get_term_breadcrumb(Term $rootTerm): array { // Setting the language here assumes all the crumbs are pages from the same language // as the root term. if (!isset($crumb['url'])) { - $crumb['url'] = Url::fromUri($crumb['uri'], ['language' => $rootTerm->language()]) - ->toString(); + $crumb['url'] = Url::fromUri($crumb['uri'], ['language' => $rootTerm->language()])->toString(); } } if (isset($crumb['title'])) {