diff --git a/core/authorize.php b/core/authorize.php index 6f64f5a..8715fb0 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -65,8 +65,8 @@ function authorize_access_allowed() { // We have to enable the user and system modules, even to check access and // display errors via the maintenance theme. -\Drupal::moduleHandler()->add('system', 'core/modules/system'); -\Drupal::moduleHandler()->add('user', 'core/modules/user'); +\Drupal::moduleHandler()->addModule('system', 'core/modules/system'); +\Drupal::moduleHandler()->addModule('user', 'core/modules/user'); \Drupal::moduleHandler()->load('system'); \Drupal::moduleHandler()->load('user'); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 23d0525..a4497a6 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -380,7 +380,7 @@ function install_begin_request(&$install_state) { $module_handler = \Drupal::moduleHandler(); if (!$module_handler->moduleExists('system')) { // Override the module list with a minimal set of modules. - $module_handler->add('system', 'core/modules/system'); + $module_handler->addModule('system', 'core/modules/system'); } // After setting up a custom and finite module list in a custom low-level // bootstrap like here, ensure to use ModuleHandler::loadAll() so that diff --git a/core/includes/install.inc b/core/includes/install.inc index 2f5e1b4..b7098b5 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -656,7 +656,7 @@ function drupal_install_system($install_state) { ->save(); // Update the module list to include it. Reboot the kernel too. - \Drupal::moduleHandler()->add('system', 'core/modules/system'); + \Drupal::moduleHandler()->addModule('system', 'core/modules/system'); $module_list = \Drupal::moduleHandler()->getModuleList(); $kernel->updateModules($module_list); diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc index a0155e0..c4b70a7 100644 --- a/core/includes/theme.maintenance.inc +++ b/core/includes/theme.maintenance.inc @@ -68,7 +68,7 @@ function _drupal_maintenance_theme() { // Ensure that system.module is loaded. if (!function_exists('_system_rebuild_theme_data')) { $module_handler = \Drupal::moduleHandler(); - $module_handler->add('system', 'core/modules/system'); + $module_handler->addModule('system', 'core/modules/system'); $module_handler->load('system'); } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 003486f..6b0d4db 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -140,10 +140,34 @@ public function setModuleList(array $module_list = array()) { $this->resetImplementations(); } - public function add($name, $path) { + /** + * {@inheritdoc} + */ + public function addModule($name, $path) { + $this->add('module', $name, $path); + } + + /** + * {@inheritdoc} + */ + public function addProfile($name, $path) { + $this->add('profile', $name, $path); + } + + /** + * Adds a module or profile to the list of currently active modules. + * + * @param string $type + * The extension type; either 'module' or 'profile'. + * @param string $name + * The module name; e.g., 'node'. + * @param string $path + * The module path; e.g., 'core/modules/node'. + */ + protected function add($type, $name, $path) { $pathname = "$path/$name.info.yml"; - $filename = file_exists($path . "/$name.module") ? "$name.module" : NULL; - $this->moduleList[$name] = new Extension('module', $pathname, $filename); + $filename = file_exists("$path/$name.$type") ? "$name.$type" : NULL; + $this->moduleList[$name] = new Extension($type, $pathname, $filename); $this->resetImplementations(); } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index 3012627..2b6d1df 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -49,24 +49,44 @@ public function isLoaded(); public function reload(); /** - * Returns a list of currently active modules. + * Returns the list of currently active modules. * - * @return array + * @return \Drupal\Core\Extension\Extension[] * An associative array whose keys are the names of the modules and whose - * values are the module filenames. + * values are Extension objects. */ public function getModuleList(); /** - * Explicitly sets the moduleList property to the passed in array of modules. + * Sets an explicit list of currently active modules. * - * @param array $module_list + * @param \Drupal\Core\Extension\Extension[] $module_list * An associative array whose keys are the names of the modules and whose - * values are the module filenames. + * values are Extension objects. */ public function setModuleList(array $module_list = array()); /** + * Adds a module to the list of currently active modules. + * + * @param string $name + * The module name; e.g., 'node'. + * @param string $path + * The module path; e.g., 'core/modules/node'. + */ + public function addModule($name, $path); + + /** + * Adds an installation profile to the list of currently active modules. + * + * @param string $name + * The profile name; e.g., 'standard'. + * @param string $path + * The profile path; e.g., 'core/profiles/standard'. + */ + public function addProfile($name, $path); + + /** * Determines which modules require and are required by each module. * * @param array $modules diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 10e0516..e3c916d 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -345,18 +345,21 @@ protected function installSchema($module, $tables) { protected function enableModules(array $modules) { // Set the list of modules in the extension handler. $module_handler = $this->container->get('module_handler'); + // Write directly to active storage to avoid early instantiation of // the event dispatcher which can prevent modules from registering events. $active_storage = \Drupal::service('config.storage'); $system_config = $active_storage->read('system.module'); + foreach ($modules as $module) { - $module_handler->add($module, drupal_get_path('module', $module)); + $module_handler->addModule($module, drupal_get_path('module', $module)); // Maintain the list of enabled modules in configuration. $system_config['enabled'][$module] = 0; } $active_storage->write('system.module', $system_config); - $module_filenames = $module_handler->getModuleList(); + // Update the kernel to make their services available. + $module_filenames = $module_handler->getModuleList(); $this->kernel->updateModules($module_filenames, $module_filenames); // Ensure isLoaded() is TRUE in order to make _theme() work. diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php index 26b1b76..a7336f9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php @@ -114,7 +114,11 @@ function testCompileDIC() { $this->assertTrue($refClass->hasMethod('loadClass'), 'Container has a classloader'); // Check that the location of the new module is registered. $modules = $container->getParameter('container.modules'); - $this->assertEqual($modules['service_provider_test'], drupal_get_filename('module', 'service_provider_test')); + $this->assertEqual($modules['service_provider_test'], array( + 'type' => 'module', + 'pathname' => drupal_get_filename('module', 'service_provider_test'), + 'filename' => NULL, + )); } } diff --git a/core/update.php b/core/update.php index 04184e5..a2de6fc 100644 --- a/core/update.php +++ b/core/update.php @@ -263,9 +263,9 @@ function update_access_allowed() { // so we fall back on requiring that the user be logged in as user #1. try { $module_handler = \Drupal::moduleHandler(); - $module_handler->add('user', 'core/modules/user'); - $module_filenames = $module_handler->getModuleList(); + $module_handler->addModule('user', 'core/modules/user'); $module_handler->reload(); + $module_filenames = $module_handler->getModuleList(); \Drupal::service('kernel')->updateModules($module_filenames, $module_filenames); return user_access('administer software updates'); }