function LanguageNegotiationUser::getLangcode
Same name in other branches
- 8.9.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::getLangcode()
- 10 core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::getLangcode()
- 11.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::getLangcode()
Overrides LanguageNegotiationMethodInterface::getLangcode
File
-
core/
modules/ user/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationUser.php, line 28
Class
- LanguageNegotiationUser
- Class for identifying language from the user preferences.
Namespace
Drupal\user\Plugin\LanguageNegotiationCode
public function getLangcode(Request $request = NULL) {
$langcode = NULL;
// User preference (only for authenticated users).
if ($this->languageManager && $this->currentUser
->isAuthenticated()) {
$preferred_langcode = $this->currentUser
->getPreferredLangcode(FALSE);
$languages = $this->languageManager
->getLanguages();
if (!empty($preferred_langcode) && isset($languages[$preferred_langcode])) {
$langcode = $preferred_langcode;
}
}
// No language preference from the user.
return $langcode;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.