You are here

public function LanguageRequestSubscriber::onKernelRequestLanguage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php \Drupal\language\EventSubscriber\LanguageRequestSubscriber::onKernelRequestLanguage()

Sets the request on the language manager.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The Event to process.

File

core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php, line 77
Contains \Drupal\language\EventSubscriber\LanguageRequestSubscriber.

Class

LanguageRequestSubscriber
Sets the $request property on the language manager.

Namespace

Drupal\language\EventSubscriber

Code

public function onKernelRequestLanguage(GetResponseEvent $event) {
  if ($event
    ->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
    $request = $event
      ->getRequest();
    $this->negotiator
      ->setCurrentUser($this->currentUser);
    $this->negotiator
      ->reset();
    if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
      $this->languageManager
        ->setNegotiator($this->negotiator);
      $this->languageManager
        ->setConfigOverrideLanguage($this->languageManager
        ->getCurrentLanguage());
    }

    // After the language manager has initialized, set the default langcode
    // for the string translations.
    $langcode = $this->languageManager
      ->getCurrentLanguage()
      ->getId();
    $this->translation
      ->setDefaultLangcode($langcode);
  }
}