Commit ccf36c37 authored by catch's avatar catch

Issue #2907546 by johndevman, Falco010: User's language preference is not applied!

(cherry picked from commit 7e77a48c)
parent 59fd099a
......@@ -242,6 +242,21 @@ public function testUILanguageNegotiation() {
];
$this->doRunTest($test);
// Set preferred langcode for user to default langcode.
$account = $this->loggedInUser;
$account->preferred_langcode = $default_language->getId();
$account->save();
$test = [
'language_negotiation' => [LanguageNegotiationUser::METHOD_ID, LanguageNegotiationUrl::METHOD_ID],
'path' => "$langcode/admin/config",
'expect' => $default_string,
'expected_method_id' => LanguageNegotiationUser::METHOD_ID,
'http_header' => [],
'message' => 'USER > URL: User has default language as preferred user language setting, the UI language is default',
];
$this->doRunTest($test);
// Set preferred langcode for user to unknown language.
$account = $this->loggedInUser;
$account->preferred_langcode = $langcode_unknown;
......
......@@ -30,10 +30,9 @@ public function getLangcode(Request $request = NULL) {
// User preference (only for authenticated users).
if ($this->languageManager && $this->currentUser->isAuthenticated()) {
$preferred_langcode = $this->currentUser->getPreferredLangcode();
$default_langcode = $this->languageManager->getDefaultLanguage()->getId();
$preferred_langcode = $this->currentUser->getPreferredLangcode(FALSE);
$languages = $this->languageManager->getLanguages();
if (!empty($preferred_langcode) && $preferred_langcode != $default_langcode && isset($languages[$preferred_langcode])) {
if (!empty($preferred_langcode) && isset($languages[$preferred_langcode])) {
$langcode = $preferred_langcode;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment