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

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
parent 16209df4
Branches
Tags
8 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards,!16Draft: Resolve #2081585 "History storage",!13Resolve #2903456
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment