Problem/Motivation
When a language does not match the language prefix (i.e. zh
and zh-hans
) and there is a redirect in place, the redirect won't be correctly resolved and the breadcrumb title and link generation will fail.
Steps to reproduce
- Have a translation for a content on a language whose id might not be the same as the URL prefix (zh and zh-hans, for example)
- Have a URL redirect
- Visit a page where a breadcrumb item points to the redirected URL. The title won't be translated, and the link will be missing.
Proposed resolution
The problem comes from this lines on getRequestForPath
. This should remove the language prefix before passing the data to the findMatchingRedirect
method.
$language_prefix = $this->languageManager->getCurrentLanguage()->getId();
if (strpos($redirect_path, "$language_prefix/") === 0) {
$redirect_path = substr($redirect_path, strlen("$language_prefix/"));
}
But, when the $language_prefix
is not the same as the url prefix, it will fail and the redirect will return nothing.
We can copy the code that is used on the build
method in order to solve the same problem, It checks the url prefixes and maps them to language IDs that might differ.
if ($prefixes = $this->languageNegotiationConfig->get('url.prefixes')) {
// Using null-coalescing to check for prefix existence for $curr_lang.
$curr_lang_prefix = $prefixes[$curr_lang] ?? '';
}
Remaining tasks
propose a MR
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet