function LanguageNegotiationUserAdmin::getLangcode
Same name and namespace in other branches
- 9 core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()
- 8.9.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()
- 11.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()
Performs language negotiation.
@todo Determine whether string|false or string|null should be the normalized result across all implementations and update the
Parameters
\Symfony\Component\HttpFoundation\Request $request: (optional) The current request. Defaults to NULL if it has not been initialized yet.
Return value
string|null|false A valid language code if the negotiation was successful and either NULL or FALSE otherwise.
and its comment accordingly.
Overrides LanguageNegotiationMethodInterface::getLangcode
File
-
core/
modules/ user/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationUserAdmin.php, line 102
Class
- LanguageNegotiationUserAdmin
- Identifies admin language from the user preferences.
Namespace
Drupal\user\Plugin\LanguageNegotiationCode
public function getLangcode(?Request $request = NULL) {
$langcode = NULL;
// User preference (only for administrators).
if (($this->currentUser
->hasPermission('access administration pages') || $this->currentUser
->hasPermission('view the administration theme')) && ($preferred_admin_langcode = $this->currentUser
->getPreferredAdminLangcode(FALSE)) && $this->isAdminPath($request)) {
$langcode = $preferred_admin_langcode;
}
// Not an admin, no admin language preference or not on an admin path.
return $langcode;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.