function AccountInterface::getPreferredLangcode

Same name in other branches
  1. 9 core/lib/Drupal/Core/Session/AccountInterface.php \Drupal\Core\Session\AccountInterface::getPreferredLangcode()
  2. 10 core/lib/Drupal/Core/Session/AccountInterface.php \Drupal\Core\Session\AccountInterface::getPreferredLangcode()
  3. 11.x core/lib/Drupal/Core/Session/AccountInterface.php \Drupal\Core\Session\AccountInterface::getPreferredLangcode()

Returns the preferred language code of the account.

Parameters

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

Return value

string Returned language code depends upon following:

  • The user preferred language code is returned if set in the account.
  • If the user has no preferred language and $fallback_to_default is TRUE then the site default language code is returned.
  • If the user has no preferred language and $fallback_to_default is FALSE then empty string is returned.
3 methods override AccountInterface::getPreferredLangcode()
AccountProxy::getPreferredLangcode in core/lib/Drupal/Core/Session/AccountProxy.php
Returns the preferred language code of the account.
User::getPreferredLangcode in core/modules/user/src/Entity/User.php
Returns the preferred language code of the account.
UserSession::getPreferredLangcode in core/lib/Drupal/Core/Session/UserSession.php
Returns the preferred language code of the account.

File

core/lib/Drupal/Core/Session/AccountInterface.php, line 86

Class

AccountInterface
Defines an account interface which represents the current user.

Namespace

Drupal\Core\Session

Code

public function getPreferredLangcode($fallback_to_default = TRUE);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.