diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index db9cdd7..5aa0ce0 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -695,7 +695,6 @@ protected function initializeContainer($rebuild = FALSE) { $request_stack = $this->container->get('request_stack'); } } - $this->container = NULL; // If the module list hasn't already been set in updateModules and we are // not forcing a rebuild, the try and load the container from the disk. @@ -710,16 +709,17 @@ protected function initializeContainer($rebuild = FALSE) { // If the load succeeded or the class already existed, use it. if (class_exists($class, FALSE)) { $fully_qualified_class_name = '\\' . $class; - $this->container = new $fully_qualified_class_name; + $container = new $fully_qualified_class_name; } } - if (!isset($this->container)) { - $this->container = $this->compileContainer(); + if (!isset($container)) { + $container = $this->compileContainer(); } - $this->attachSynthetic($this->container, $request, $request_stack, $request_scope); + $this->attachSynthetic($container, $request, $request_stack, $request_scope); + $this->container = $container; \Drupal::setContainer($this->container); return $this->container; } diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index ee501ce..e8afbef 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1107,7 +1107,7 @@ protected function writeCustomTranslations() { * @see TestBase::prepareEnvironment() * @see TestBase::restoreEnvironment() * - * @todo Fix http://drupal.org/node/1708692 so that module enable/disable + * @todo Fix https://www.drupal.org/node/2021959 so that module enable/disable * changes are immediately reflected in \Drupal::getContainer(). Until then, * tests can invoke this workaround when requiring services from newly * enabled modules to be immediately available in the same request. @@ -1115,8 +1115,10 @@ protected function writeCustomTranslations() { protected function rebuildContainer() { // Maintain the current global request object. $request = \Drupal::request(); + // Kernel doesn't update module list during rebuild so force a rebuild. + $this->kernel->updateModules(\Drupal::moduleHandler()->getModuleList()); // Rebuild the kernel and bring it back to a fully bootstrapped state. - $this->container = $this->kernel->rebuildContainer(); + $this->container = $this->kernel->getContainer(); $this->container->get('current_user')->setAccount(\Drupal::currentUser()); // The request context is normally set by the router_listener from within