function LanguageNegotiationSession::persist
Same name in other branches
- 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::persist()
- 8.9.x core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::persist()
- 10 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::persist()
Overrides LanguageNegotiationMethodBase::persist
File
-
core/
modules/ language/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationSession.php, line 101
Class
- LanguageNegotiationSession
- Identify language from a request/session parameter.
Namespace
Drupal\language\Plugin\LanguageNegotiationCode
public function persist(LanguageInterface $language) {
// We need to update the session parameter with the request value only if we
// have an authenticated user.
$langcode = $language->getId();
if ($langcode && $this->languageManager) {
$languages = $this->languageManager
->getLanguages();
if ($this->currentUser
->isAuthenticated() && isset($languages[$langcode])) {
$config = $this->config
->get('language.negotiation')
->get('session');
$this->requestStack
->getCurrentRequest()
->getSession()
->set($config['parameter'], $langcode);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.