- Issue created by @Remco Hoeneveld
- 🇳🇱Netherlands seanB Netherlands
This is indeed an issue. A little more context. The following calls lead to the issue:
HtmlLink::parseEntitiesFromText()
EntityUsageBase::findEntityByUrlString()
EntityUsageBase::processUrl()
PathValidator::getUrlIfValidWithoutAccessCheck()
PathValidator::getUrl()
PathValidator::getPathAttributes()
PathProcessorManager::processInbound()
AliasPathProcessor::processInbound()
AliasManager::getPathByAlias()
The
AliasPathProcessor::processInbound()
doesn't pass a langcode toAliasManager::getPathByAlias()
, and for that reasonAliasManager::getPathByAlias()
uses the current language from the URL. If you link to a page in another language this is an issue, but also if the langcode in the URL is different for other reasons (like working on translations or something).The current patch has some issues though.
-
+++ b/src/EntityUsageBase.php @@ -9,11 +9,15 @@ use Drupal\Core\Entity\EntityRepositoryInterface; +use Drupal\path_alias\AliasManagerInterface;
We don't have a hard dependency on the path_alias module, and we should not add it just for this bug.
-
+++ b/src/EntityUsageBase.php @@ -363,4 +402,29 @@ abstract class EntityUsageBase extends EntityTrackBase { + protected function processUrlForAllLanguages(string &$url): void { + $languages = $this->languageManager->getLanguages(); + $request = Request::create($url); + $resolved_path = $this->pathProcessorManager->processInbound($url, $request); + foreach ($languages as $language) { + $alias = $this->aliasManager->getPathByAlias( + $resolved_path, + $language->getId());
This works around the issue, but duplicates a bunch of code. The real issue is the
LanguageNegotiationUrl
inbound path processor strips the language prefix from the URL, and theAliasPathProcessor
is not able to pass the langcode (when available). It seems there already is a core issue to fix this: #3314941: Language-prefixed alias paths cannot be correctly routed inside a request →
Could you try if #3314941: Language-prefixed alias paths cannot be correctly routed inside a request → fixes the issue?
-