You are here

public function LanguageNegotiationUserAdmin::getLangcode in Drupal 9

Same name and namespace in other branches
  1. 8 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\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;
}