diff --git a/src/EventSubscriber/RedirectRequestSubscriber.php b/src/EventSubscriber/RedirectRequestSubscriber.php index cacd951..312d04e 100644 --- a/src/EventSubscriber/RedirectRequestSubscriber.php +++ b/src/EventSubscriber/RedirectRequestSubscriber.php @@ -242,7 +242,7 @@ public function redirectNormalizeAliases(GetResponseEvent $event) { return; } - + $path = $this->cleanPathFromLanguagePrefix($path); $system_path = $this->aliasManager->getPathByAlias($path); $alias = $this->aliasManager->getAliasByPath($system_path, $this->languageManager->getCurrentLanguage() ->getId()); @@ -256,6 +256,23 @@ public function redirectNormalizeAliases(GetResponseEvent $event) { } } + public function cleanPathFromLanguagePrefix($path) { + $config = \Drupal::config('language.negotiation')->get('url'); + $parts = explode('/', trim($path, '/')); + $prefix = array_shift($parts); + + // Search prefix within added languages. + foreach (\Drupal::languageManager()->getLanguages() as $language) { + if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) { + // Rebuild $path with the language removed. + $path = '/' . implode('/', $parts); + break; + } + } + + return $path; + } + /** * Redirects forum taxonomy terms to correct forum path. *