public function LanguageNegotiationUserAdmin::getLangcode in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()
Performs language negotiation.
Parameters
\Symfony\Component\HttpFoundation\Request $request: (optional) The current request. Defaults to NULL if it has not been initialized yet.
Return value
string A valid language code or FALSE if the negotiation was unsuccessful.
Overrides LanguageNegotiationMethodInterface::getLangcode
File
- core/
modules/ user/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationUserAdmin.php, line 100
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;
}