Redirection issue when interface language is different from content language

Created on 8 August 2018, over 6 years ago
Updated 18 February 2025, 11 days ago

Context:
In my project, I force interface language to be always the same ; it helps content manager to get the interface in a language they know (sometimes they have to fix few things in a language they don't know so it helps).

Problem:
If interface language (let's say English) and content language (let's say Chinese) don't match, if there is a redirection for the current URL (in Chinese), it won't match anything in the DB since it searches for a match in the DB with interface language (English).

In "src/EventSubscriber/RedirectRequestSubscriber.php" at line 137 we have :

$redirect = $this->redirectRepository->findMatchingRedirect($path, $request_query, $this->languageManager->getCurrentLanguage()->getId());

and "getCurrentLanguage" code is :

public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE)

so it takes interface language and there is no match.

Solution:

Use "getCurrentLanguage" with "LanguageInterface::TYPE_CONTENT" as param.

Questions:
Any impact? Or is there any reason to use the interface language?

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇫🇷France progzy

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024