You are here

public function LanguageNegotiationSession::getLangcode in Zircon Profile 8.0

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

Performs language negotiation.

Parameters

\Symfony\Component\HttpFoundation\Request $request: (optional) The current request. Defaults to NULL if it has not been initialized yet.

Return value

string A valid language code or FALSE if the negotiation was unsuccessful.

Overrides LanguageNegotiationMethodInterface::getLangcode

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php, line 60
Contains \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession.

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');
  $param = $config['parameter'];
  $langcode = $request && $request->query
    ->get($param) ? $request->query
    ->get($param) : NULL;
  if (!$langcode && isset($_SESSION[$param])) {
    $langcode = $_SESSION[$param];
  }
  return $langcode;
}