Skip to content
Snippets Groups Projects
Commit cde72309 authored by catch's avatar catch
Browse files

Issue #1846376 by effulgentsia, amateescu | katbailey: Fixed Namespaces for...

Issue #1846376 by effulgentsia, amateescu | katbailey: Fixed Namespaces for disabled modules are registered during the first request after a module is disabled.
parent 130b8e3c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -192,7 +192,7 @@ public function registerBundles() { ...@@ -192,7 +192,7 @@ public function registerBundles() {
// When installing new modules, the modules in the list passed to // When installing new modules, the modules in the list passed to
// updateModules() do not yet have their namespace registered. // updateModules() do not yet have their namespace registered.
$namespace = 'Drupal\\' . $module; $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'; $path = dirname(DRUPAL_ROOT . '/' . $this->moduleData($module)->uri) . '/lib';
$this->modulePaths[$module] = $path; $this->modulePaths[$module] = $path;
$this->classLoader->registerNamespace($namespace, $path); $this->classLoader->registerNamespace($namespace, $path);
...@@ -319,15 +319,20 @@ protected function initializeContainer() { ...@@ -319,15 +319,20 @@ protected function initializeContainer() {
// All namespaces must be registered before we attempt to use any service // All namespaces must be registered before we attempt to use any service
// from the container. // from the container.
$namespaces = $this->classLoader->getNamespaces(); $namespaces = $this->classLoader->getNamespaces();
$namespaces_revert = array();
foreach ($this->container->getParameter('container.modules') as $module => $path) { foreach ($this->container->getParameter('container.modules') as $module => $path) {
$namespace = 'Drupal\\' . $module; $namespace = 'Drupal\\' . $module;
if (!isset($namespaces[$namespace])) { if (empty($namespaces[$namespace])) {
$this->classLoader->registerNamespace($namespace, $path); $this->classLoader->registerNamespace($namespace, $path);
$namespaces_revert[$namespace] = array();
} }
} }
$module_list = $this->moduleList ?: $this->container->get('config.factory')->get('system.module')->load()->get('enabled'); $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'))) { if (array_keys((array)$module_list) !== array_keys($this->container->getParameter('container.modules'))) {
unset($this->container); unset($this->container);
// Since 'container.modules' was incorrect, revert the classloader
// registrations, and allow buildContainer() to get it right.
$this->classLoader->registerNamespaces($namespaces_revert);
} }
} }
......
...@@ -37,16 +37,10 @@ function testClassLoading() { ...@@ -37,16 +37,10 @@ function testClassLoading() {
module_disable(array('module_autoload_test'), FALSE); module_disable(array('module_autoload_test'), FALSE);
$this->resetAll(); $this->resetAll();
// The first request after a module has been disabled will result in that // Check twice to test an unprimed and primed system_list() cache.
// 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
for ($i=0; $i<2; $i++) { for ($i=0; $i<2; $i++) {
$this->drupalGet('module-test/class-loading'); $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.');
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment