diff -u b/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php --- b/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -916,6 +916,7 @@ // new session into the master request if one was present before. if (($request_stack = $this->container->get('request_stack', ContainerInterface::NULL_ON_INVALID_REFERENCE))) { if ($request = $request_stack->getMasterRequest()) { + $subrequest = TRUE; if ($request->hasSession()) { $request->setSession($this->container->get('session')); } @@ -928,9 +929,10 @@ \Drupal::setContainer($this->container); - // If there is a request stack, we want to make sure other parts of the - // codebase can react to this. - if ($request) { - $this->container->get('event_dispatcher')->dispatch(self::CONTAINER_INITIALIZE_FINISHED); + + // Allow other parts of the codebase to react on container initialization in + // subrequest. + if (isset($subrequest) && $subrequest) { + $this->container->get('event_dispatcher')->dispatch(self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED); } // If needs dumping flag was set, dump the container. diff -u b/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php --- b/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -15,14 +15,14 @@ interface DrupalKernelInterface extends HttpKernelInterface, ContainerAwareInterface { /** - * Name of the event fired when the service container finished initializing. + * Event fired when the service container finished initializing in subrequest. * * This event allows you to initialize overrides such as language to the * services. * * @var string */ - const CONTAINER_INITIALIZE_FINISHED = 'kernel.container.finish_container_initialize'; + const CONTAINER_INITIALIZE_SUBREQUEST_FINISHED = 'kernel.container.finish_container_initialize_subrequest'; /** * Boots the current kernel. diff -u b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php --- b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php +++ b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php @@ -79,7 +79,7 @@ /** * Initializes config overrides whenever the service container is rebuilt. */ - public function onContainerInitializeFinished() { + public function onContainerInitializeSubrequestFinished() { $this->setLanguageOverrides(); } @@ -106,7 +106,7 @@ */ public static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = ['onKernelRequestLanguage', 255]; - $events[DrupalKernelInterface::CONTAINER_INITIALIZE_FINISHED][] = array('onContainerInitializeFinished', 255); + $events[DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED][] = ['onContainerInitializeSubrequestFinished', 255]; return $events; }