diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index c0bc608..0c38b5f 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2476,12 +2476,10 @@ function drupal_container(Container $new_container = NULL) { /** * Retrieves the ExtensionHandler that manages the list of enabled modules. * - * This is a temporary function that will instantiate a new ExtensionHandler if - * there isn't one present in the container. This will only happen if the - * boostrap container is being used, e.g. during installation. - * @todo Remove this and convert all calls to it to - * drupal_container()->get('extension_handler') once the installer and the - * run-tests.sh script are using a Kernel. + * This function instantiates a new ExtensionHandlerMinimal if there is no + * 'extension_handler' service in the container. This is currently needed for + * running tests. + * @todo Figure out how to get tests to run without using this. * * @return Drupal\Core\ExtensionHandlerInterface */ @@ -2500,18 +2498,6 @@ function drupal_extension_handler() { } /** - * Returns a list of currently active modules. - * - * @see ExtensionHandler::moduleList(). - */ -function module_list($type = 'module_enabled', array $fixed_list = NULL, $reset = FALSE) { - if ($type == 'bootstrap') { - return drupal_extension_handler()->getBootstrapModules(); - } - return drupal_extension_handler()->getEnabledModules(); -} - -/** * Loads all the modules that have been enabled in the system table. * * @see ExtensionHandler::loadAll(). diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index f4c5bfe..9c059a2 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -330,6 +330,9 @@ function install_begin_request(&$install_state) { $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') ->addArgument(new Reference('config.storage')) ->addArgument(new Reference('dispatcher')); + // Register an extension handler for managing enabled modules. + $container + ->register('extension_handler', 'Drupal\Core\ExtensionHandlerMinimal'); drupal_container($container); } diff --git a/core/lib/Drupal/Core/ExtensionHandler.php b/core/lib/Drupal/Core/ExtensionHandler.php index ac1b2dc..66c2150 100644 --- a/core/lib/Drupal/Core/ExtensionHandler.php +++ b/core/lib/Drupal/Core/ExtensionHandler.php @@ -83,8 +83,9 @@ public function load($name) { if (isset($this->loadedFiles[$name])) { return TRUE; } - $filename = $this->moduleList[$name]; - if ($filename) { + + if (isset($this->moduleList[$name])) { + $filename = $this->moduleList[$name]; include_once DRUPAL_ROOT . '/' . $filename; $this->loadedFiles[$name] = TRUE; return TRUE; diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php b/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php index ac55787..9f803de 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php @@ -42,20 +42,6 @@ class Layout implements DerivativeInterface { protected $type = 'static'; /** - * The extension handler for retieving the list of enabled modules. - * - * @var \Drupal\Core\ExtensionHandlerInterface - */ - protected $extensionHandler; - - /** - * Constructor. - */ - public function __construct(ExtensionHandlerInterface $extension_handler) { - $this->extensionHandler = $extension_handler; - } - - /** * Implements DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { @@ -73,7 +59,9 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { $available_layout_providers = array(); // Add all modules as possible layout providers. - foreach ($this->extensionHandler->getEnabledModules() as $module => $filename) { + // @todo Change this class so that it gets the extension handler injected + // into it. + foreach (drupal_extension_handler()->getEnabledModules() as $module => $filename) { $available_layout_providers[$module] = array( 'type' => 'module', 'provider' => $module, diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 83403b4..430dbe0 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -147,8 +147,7 @@ public function containerBuild($container) { } // Register an extension handler for managing enabled modules. $container - ->register('extension_handler', 'Drupal\Core\ExtensionHandlerMinimal') - ->addArgument(array('system' => 'core/modules/system/system.module')); + ->register('extension_handler', 'Drupal\Core\ExtensionHandlerMinimal'); } /** @@ -206,12 +205,11 @@ protected function installSchema($module, $table) { * implementation that is able to manage a fixed module list. */ protected function enableModules(array $modules, $install = TRUE) { - // Set the modules in the fixed module list. + // Explicitly set the list of modules in the extension handler. $new_enabled = array(); $extension_handler = $this->container->get('extension_handler'); foreach ($modules as $module) { $this->moduleList[$module] = drupal_get_filename('module', $module); - $new_enabled[$module] = dirname($this->moduleList[$module]['filename']); $this->container->get('extension_handler')->setModuleList($this->moduleList); // Call module_enable() to enable (install) the new module. @@ -222,7 +220,7 @@ protected function enableModules(array $modules, $install = TRUE) { // Otherwise, only ensure that the new modules are loaded. if (!$install) { module_load_all(FALSE, TRUE); - module_implements_reset(); + $extension_handler->moduleImplementsReset(); } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php index 5813ffd..5ca7c71 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php @@ -39,7 +39,7 @@ function testSetUp() { // Verify that specified $modules have been loaded. $this->assertTrue(function_exists('entity_test_permission'), "$module.module was loaded."); // Verify that there is a fixed module list. - $this->assertIdentical(module_list(), array($module => $module)); + $this->assertIdentical(array_keys(drupal_extension_handler()->getEnabledModules()), array($module)); $this->assertIdentical(module_implements('permission'), array($module)); // Verify that no modules have been installed. @@ -54,9 +54,9 @@ function testEnableModulesLoad() { // Verify that the module does not exist yet. $this->assertFalse(module_exists($module), "$module module not found."); - $list = module_list(); - $this->assertFalse(in_array($module, $list), "$module module in module_list() not found."); - $list = module_list('permission'); + $list = array_keys(drupal_extension_handler()->getEnabledModules()); + $this->assertFalse(in_array($module, $list), "$module module not found in the extension handler's module list."); + $list = module_implements('permission'); $this->assertFalse(in_array($module, $list), "{$module}_permission() in module_implements() not found."); // Enable the module. @@ -64,9 +64,9 @@ function testEnableModulesLoad() { // Verify that the module exists. $this->assertTrue(module_exists($module), "$module module found."); - $list = module_list(); - $this->assertTrue(in_array($module, $list), "$module module in module_list() found."); - $list = module_list('permission'); + $list = array_keys(drupal_extension_handler()->getEnabledModules()); + $this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list."); + $list = module_implements('permission'); $this->assertTrue(in_array($module, $list), "{$module}_permission() in module_implements() found."); } @@ -83,9 +83,9 @@ function testEnableModulesInstall() { // Verify that the module does not exist yet. $this->assertFalse(module_exists($module), "$module module not found."); - $list = module_list(); - $this->assertFalse(in_array($module, $list), "$module module in module_list() not found."); - $list = module_list('permission'); + $list = array_keys(drupal_extension_handler()->getEnabledModules()); + $this->assertFalse(in_array($module, $list), "$module module not found in the extension handler's module list."); + $list = module_implements('permission'); $this->assertFalse(in_array($module, $list), "{$module}_permission() in module_implements() not found."); $this->assertFalse(db_table_exists($table), "'$table' database table not found."); @@ -97,9 +97,9 @@ function testEnableModulesInstall() { // Verify that the enabled module exists. $this->assertTrue(module_exists($module), "$module module found."); - $list = module_list(); - $this->assertTrue(in_array($module, $list), "$module module in module_list() found."); - $list = module_list('permission'); + $list = array_keys(drupal_extension_handler()->getEnabledModules()); + $this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list."); + $list = module_implements('permission'); $this->assertTrue(in_array($module, $list), "{$module}_permission() in module_implements() found."); $this->assertTrue(db_table_exists($table), "'$table' database table found."); diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/EnableDisableTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/EnableDisableTest.php index 423b582..5e28d84 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/EnableDisableTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/EnableDisableTest.php @@ -23,6 +23,7 @@ public static function getInfo() { * Tests that all core modules can be enabled, disabled and uninstalled. */ function testEnableDisable() { + // Try to enable, disable and uninstall all core modules, unless they are // hidden or required. $modules = system_rebuild_module_data(); @@ -90,10 +91,12 @@ function testEnableDisable() { $edit = array(); $edit['modules[Core][' . $name . '][enable]'] = $name; $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->rebuildContainer(); // Handle the case where modules were installed along with this one and // where we therefore hit a confirmation screen. if (count($modules_to_enable) > 1) { $this->drupalPost(NULL, array(), t('Continue')); + $this->rebuildContainer(); } $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.'); @@ -162,6 +165,7 @@ function testEnableDisable() { $edit['modules[Core][' . $name . '][enable]'] = $name; } $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->rebuildContainer(); $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.'); } @@ -176,6 +180,7 @@ function assertSuccessfulDisableAndUninstall($module) { $edit = array(); $edit['modules[Core][' . $module . '][enable]'] = FALSE; $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->rebuildContainer(); $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.'); $this->assertModules(array($module), FALSE); @@ -194,6 +199,7 @@ function assertSuccessfulDisableAndUninstall($module) { $edit['uninstall[' . $module . ']'] = $module; $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall')); $this->drupalPost(NULL, NULL, t('Uninstall')); + $this->rebuildContainer(); $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.'); $this->assertModules(array($module), FALSE); diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php index d139123..a16c49f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php @@ -25,7 +25,7 @@ public static function getInfo() { } /** - * The basic functionality of module_list(). + * The basic functionality of retrieving enabled modules. */ function testModuleList() { // Build a list of modules, sorted alphabetically. @@ -36,8 +36,8 @@ function testModuleList() { $module_list[] = 'standard'; sort($module_list); - // Compare this list to the one returned by module_list(). We expect them - // to match, since all default profile modules have a weight equal to 0 + // Compare this list to the one returned by the extension handler. We expect + // them to match, since all default profile modules have a weight equal to 0 // (except for block.module, which has a lower weight but comes first in // the alphabet anyway). $this->assertModuleList($module_list, t('Standard profile')); @@ -68,7 +68,7 @@ function testModuleList() { } /** - * Assert that module_list() return the expected values. + * Assert that the extension handler returns the expected values. * * @param $expected_values * The expected values, sorted by weight and module name. @@ -76,7 +76,7 @@ function testModuleList() { protected function assertModuleList(Array $expected_values, $condition) { $expected_values = array_values(array_unique($expected_values)); $enabled_modules = array_keys($this->container->get('extension_handler')->getEnabledModules()); - $this->assertEqual($expected_values, $enabled_modules, format_string('@condition: module_list() returns correct results', array('@condition' => $condition))); + $this->assertEqual($expected_values, $enabled_modules, format_string('@condition: extension handler returns correct results', array('@condition' => $condition))); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php index d8425c1..1fc541f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php @@ -146,7 +146,7 @@ function assertModules(array $modules, $enabled) { else { $message = 'Module "@module" is not enabled.'; } - $this->assertEqual(module_exists($module), $enabled, format_string($message, array('@module' => $module))); + $this->assertEqual($this->container->get('extension_handler')->moduleExists($module), $enabled, format_string($message, array('@module' => $module))); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/ModulesDisabledUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ModulesDisabledUpgradePathTest.php index c4c6f75..24531de 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/ModulesDisabledUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ModulesDisabledUpgradePathTest.php @@ -37,7 +37,7 @@ public function testDisabledUpgrade() { $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); // Get enabled modules. - $enabled = module_list(); + $enabled = drupal_extension_handler()->getEnabledModules(); // Get all available modules. $available = system_rebuild_module_data(); // Filter out hidden test modules.