class LanguageNegotiationUser in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser
Class for identifying language from the user preferences.
Plugin annotation
@LanguageNegotiation(
id = \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::METHOD_ID,
weight = -4,
name = @Translation("User"),
description = @Translation("Follow the user's language preference.")
)
Hierarchy
- class \Drupal\language\LanguageNegotiationMethodBase implements LanguageNegotiationMethodInterface
- class \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser
Expanded class hierarchy of LanguageNegotiationUser
2 files declare their use of LanguageNegotiationUser
- AccountForm.php in core/
modules/ user/ src/ AccountForm.php - LanguageUILanguageNegotiationTest.php in core/
modules/ language/ tests/ src/ Functional/ LanguageUILanguageNegotiationTest.php
File
- core/
modules/ user/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationUser.php, line 18
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;
}
}