LanguageNegotiationUser.php in Zircon Profile 8.0
File
core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php
View source
<?php
namespace Drupal\user\Plugin\LanguageNegotiation;
use Drupal\language\LanguageNegotiationMethodBase;
use Symfony\Component\HttpFoundation\Request;
class LanguageNegotiationUser extends LanguageNegotiationMethodBase {
const METHOD_ID = 'language-user';
public function getLangcode(Request $request = NULL) {
$langcode = NULL;
if ($this->languageManager && $this->currentUser
->isAuthenticated()) {
$preferred_langcode = $this->currentUser
->getPreferredLangcode();
$default_langcode = $this->languageManager
->getDefaultLanguage()
->getId();
$languages = $this->languageManager
->getLanguages();
if (!empty($preferred_langcode) && $preferred_langcode != $default_langcode && isset($languages[$preferred_langcode])) {
$langcode = $preferred_langcode;
}
}
return $langcode;
}
}