function LanguageNegotiationSession::getLangcode

Same name and namespace in other branches
  1. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::getLangcode()
  2. 8.9.x core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::getLangcode()
  3. 10 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::getLangcode()

Overrides LanguageNegotiationMethodInterface::getLangcode

File

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

Class

LanguageNegotiationSession
Identify language from a request/session parameter.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

public function getLangcode(?Request $request = NULL) {
    $config = $this->config
        ->get('language.negotiation')
        ->get('session');
    if (($param = $config['parameter']) && $request) {
        if ($request->query
            ->has($param)) {
            return $request->query
                ->get($param);
        }
        if ($request->getSession()
            ->has($param)) {
            return $request->getSession()
                ->get($param);
        }
    }
    return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.