From cde72309be9984a165421af27cc77d42702ff2b9 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 26 Nov 2012 10:32:47 +0000 Subject: [PATCH] Issue #1846376 by effulgentsia, amateescu | katbailey: Fixed Namespaces for disabled modules are registered during the first request after a module is disabled. --- core/lib/Drupal/Core/DrupalKernel.php | 9 +++++++-- .../lib/Drupal/system/Tests/Module/ClassLoaderTest.php | 10 ++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index a5624d700435..f07d081fad43 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 ea2026d0522d..df59ea08d8aa 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.'); } } -- GitLab