function LanguageNegotiationUserAdmin::getLangcode

Same name and namespace in other branches
  1. 8.9.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()
  2. 10 core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()
  3. 11.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::getLangcode()

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\LanguageNegotiation

Code

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.