class LanguageNegotiationUser
Same name in other branches
- 9 core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser
- 8.9.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser
- 11.x core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser
Class for identifying language from the user preferences.
Hierarchy
- class \Drupal\language\LanguageNegotiationMethodBase implements \Drupal\language\LanguageNegotiationMethodInterface
- class \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser extends \Drupal\language\LanguageNegotiationMethodBase
Expanded class hierarchy of LanguageNegotiationUser
4 files declare their use of LanguageNegotiationUser
- AccountForm.php in core/
modules/ user/ src/ AccountForm.php - BookMultilingualTest.php in core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php - LanguageUILanguageNegotiationTest.php in core/
modules/ language/ tests/ src/ Functional/ LanguageUILanguageNegotiationTest.php - PathLanguageTest.php in core/
modules/ path/ tests/ src/ Functional/ PathLanguageTest.php
File
-
core/
modules/ user/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationUser.php, line 13
Namespace
Drupal\user\Plugin\LanguageNegotiationView source
class LanguageNegotiationUser extends LanguageNegotiationMethodBase {
/**
* The language negotiation method id.
*/
const METHOD_ID = 'language-user';
/**
* {@inheritdoc}
*/
public function getLangcode(?Request $request = NULL) {
$langcode = NULL;
// User preference (only for authenticated users).
if ($this->languageManager && $this->currentUser
->isAuthenticated()) {
$preferred_langcode = $this->currentUser
->getPreferredLangcode(FALSE);
$languages = $this->languageManager
->getLanguages();
if (!empty($preferred_langcode) && isset($languages[$preferred_langcode])) {
$langcode = $preferred_langcode;
}
}
// No language preference from the user.
return $langcode;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.