Commit 200cef5a authored by catch's avatar catch

Issue #3144354 by alexpott, vijaycs85, andypost: ModuleInstaller loads .module...

Issue #3144354 by alexpott, vijaycs85, andypost: ModuleInstaller loads .module and .install before allowing classes to autoloaded

(cherry picked from commit 1a48485e)
parent 8a9cfeb4
......@@ -193,14 +193,9 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
}
}
// Update the module handler in order to load the module's code.
// This allows the module to participate in hooks and its existence to
// be discovered by other modules.
// The current ModuleHandler instance is obsolete with the kernel
// rebuild below.
// Update the module handler in order to have the correct module list
// for the kernel update.
$this->moduleHandler->setModuleList($module_filenames);
$this->moduleHandler->load($module);
module_load_install($module);
// Clear the static cache of the "extension.list.module" service to pick
// up the new module, since it merges the installation status of modules
......@@ -210,6 +205,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// Update the kernel to include it.
$this->updateKernel($module_filenames);
// Load the module's .module and .install files.
$this->moduleHandler->load($module);
module_load_install($module);
// Replace the route provider service with a version that will rebuild
// if routes used during installation. This ensures that a module's
// routes are available during installation. This has to occur before
......
<?php
/**
* @file
* Test module.
*/
use Drupal\module_autoload_test\SomeClass;
define('MODULE_AUTOLOAD_TEST_CONSTANT', SomeClass::TEST);
......@@ -4,6 +4,8 @@
class SomeClass {
const TEST = '\Drupal\module_autoload_test\SomeClass::TEST';
public function testMethod() {
return 'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.';
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\system\Functional\Module;
use Drupal\module_autoload_test\SomeClass;
use Drupal\Tests\BrowserTestBase;
/**
......@@ -96,4 +97,19 @@ public function testMultipleModules() {
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('module_install_class_loader_test2'), 'The module_install_class_loader_test2 module has been installed.');
}
/**
* Tests that .module files can use class constants in main section.
*/
public function testAutoloadFromModuleFile() {
$this->assertFalse(defined('MODULE_AUTOLOAD_TEST_CONSTANT'));
$this->drupalLogin($this->rootUser);
$edit = [
"modules[module_autoload_test][enable]" => TRUE,
];
$this->drupalPostForm('admin/modules', $edit, t('Install'));
$this->assertSession()->statusCodeEquals(200);
$this->resetAll();
$this->assertSame(SomeClass::TEST, MODULE_AUTOLOAD_TEST_CONSTANT);
}
}
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