Commit cde72309 authored by catch's avatar catch

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
......@@ -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);
}
}
......
......@@ -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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment