Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LanguageNegotiationSession.php

function 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\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');
            $this->requestStack
                ->getCurrentRequest()
                ->getSession()
                ->set($config['parameter'], $langcode);
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal