You are here

public function LanguageNegotiationSession::persist in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::persist()
  2. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::persist()

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php, line 68

Class

LanguageNegotiationSession
Identify language from a request/session parameter.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

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');
      $_SESSION[$config['parameter']] = $langcode;
    }
  }
}