diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index a5624d700435c8e7a939e179db0378a14556f07a..f07d081fad4304853c961750691761f0a533242a 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -192,7 +192,7 @@ public function registerBundles() { // When installing new modules, the modules in the list passed to // updateModules() do not yet have their namespace registered. $namespace = 'Drupal\\' . $module; - if (!isset($namespaces[$namespace]) && $this->moduleData($module)) { + if (empty($namespaces[$namespace]) && $this->moduleData($module)) { $path = dirname(DRUPAL_ROOT . '/' . $this->moduleData($module)->uri) . '/lib'; $this->modulePaths[$module] = $path; $this->classLoader->registerNamespace($namespace, $path); @@ -319,15 +319,20 @@ protected function initializeContainer() { // All namespaces must be registered before we attempt to use any service // from the container. $namespaces = $this->classLoader->getNamespaces(); + $namespaces_revert = array(); foreach ($this->container->getParameter('container.modules') as $module => $path) { $namespace = 'Drupal\\' . $module; - if (!isset($namespaces[$namespace])) { + if (empty($namespaces[$namespace])) { $this->classLoader->registerNamespace($namespace, $path); + $namespaces_revert[$namespace] = array(); } } $module_list = $this->moduleList ?: $this->container->get('config.factory')->get('system.module')->load()->get('enabled'); if (array_keys((array)$module_list) !== array_keys($this->container->getParameter('container.modules'))) { unset($this->container); + // Since 'container.modules' was incorrect, revert the classloader + // registrations, and allow buildContainer() to get it right. + $this->classLoader->registerNamespaces($namespaces_revert); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ClassLoaderTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/ClassLoaderTest.php index ea2026d0522d969d90bd7ed0d9060ade3d62d173..df59ea08d8aae98d7a992c536f9676896deeb85e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ClassLoaderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ClassLoaderTest.php @@ -37,16 +37,10 @@ function testClassLoading() { module_disable(array('module_autoload_test'), FALSE); $this->resetAll(); - // The first request after a module has been disabled will result in that - // module's namespace getting registered because the kernel registers all - // namespaces in the existing 'container.modules' parameter before checking - // whether the list of modules has changed and rebuilding the container. - // @todo Fix the behavior so that the namespace is not registered even on the - // first request after disabling the module and revert this test to having - // the assertion inside the loop. See http://drupal.org/node/1846376 + // Check twice to test an unprimed and primed system_list() cache. for ($i=0; $i<2; $i++) { $this->drupalGet('module-test/class-loading'); + $this->assertNoText($expected, 'Autoloader does not load classes from a disabled module.'); } - $this->assertNoText($expected, 'Autoloader does not load classes from a disabled module.'); } }