You are here

function User::getPreferredAdminLangcode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Entity/User.php \Drupal\user\Entity\User::getPreferredAdminLangcode()

Returns the preferred administrative language code of the account.

Defines which language is used on administrative pages.

Parameters

bool $fallback_to_default: (optional) Whether the return value will fall back to the site default language if the user has no administration language preference.

Return value

string The language code that is preferred by the account for administration pages. If the preferred language is not set or is a language not configured anymore on the site, the site default is returned or an empty string is returned (if $fallback_to_default is FALSE).

Overrides AccountInterface::getPreferredAdminLangcode

File

core/modules/user/src/Entity/User.php, line 330
Contains \Drupal\user\Entity\User.

Class

User
Defines the user entity class.

Namespace

Drupal\user\Entity

Code

function getPreferredAdminLangcode($fallback_to_default = TRUE) {
  $language_list = $this
    ->languageManager()
    ->getLanguages();
  $preferred_langcode = $this
    ->get('preferred_admin_langcode')->value;
  if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) {
    return $language_list[$preferred_langcode]
      ->getId();
  }
  else {
    return $fallback_to_default ? $this
      ->languageManager()
      ->getDefaultLanguage()
      ->getId() : '';
  }
}