Chris@0: languageManager = $language_manager; Chris@0: $this->negotiator = $negotiator; Chris@0: $this->translation = $translation; Chris@0: $this->currentUser = $current_user; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Initializes the language manager at the beginning of the request. Chris@0: * Chris@0: * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event Chris@0: * The Event to process. Chris@0: */ Chris@0: public function onKernelRequestLanguage(GetResponseEvent $event) { Chris@18: if ($event->isMasterRequest()) { Chris@0: $this->setLanguageOverrides(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Initializes config overrides whenever the service container is rebuilt. Chris@0: */ Chris@0: public function onContainerInitializeSubrequestFinished() { Chris@0: $this->setLanguageOverrides(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the language for config overrides on the language manager. Chris@0: */ Chris@0: private function setLanguageOverrides() { Chris@0: $this->negotiator->setCurrentUser($this->currentUser); Chris@0: if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) { Chris@0: $this->languageManager->setNegotiator($this->negotiator); Chris@0: $this->languageManager->setConfigOverrideLanguage($this->languageManager->getCurrentLanguage()); Chris@0: } Chris@0: // After the language manager has initialized, set the default langcode for Chris@0: // the string translations. Chris@0: $langcode = $this->languageManager->getCurrentLanguage()->getId(); Chris@0: $this->translation->setDefaultLangcode($langcode); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Registers the methods in this class that should be listeners. Chris@0: * Chris@0: * @return array Chris@0: * An array of event listener definitions. Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: $events[KernelEvents::REQUEST][] = ['onKernelRequestLanguage', 255]; Chris@0: $events[DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED][] = ['onContainerInitializeSubrequestFinished', 255]; Chris@0: Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }