diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 28c0b28..19c2dd1 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2419,7 +2419,7 @@ function _drupal_bootstrap_variables() { $conf = variable_initialize(isset($conf) ? $conf : array()); // Load bootstrap modules. require_once DRUPAL_ROOT . '/core/includes/module.inc'; - module_load_all(TRUE); + drupal_container()->get('extension_handler')->loadBootstrap(); } /** @@ -2472,16 +2472,6 @@ function drupal_container(Container $new_container = NULL) { return $container; } - -/** - * Loads all the modules that have been enabled in the system table. - * - * @see ExtensionHandler::loadAll(). - */ -function module_load_all($bootstrap = FALSE, $reset = FALSE, $loaded = FALSE) { - return drupal_container()->get('extension_handler')->loadAll($bootstrap, $reset, $loaded); -} - /** * Determines which modules are implementing a hook. * diff --git a/core/includes/common.inc b/core/includes/common.inc index 17b664d..3acc902 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4774,7 +4774,7 @@ function _drupal_bootstrap_code() { require_once DRUPAL_ROOT . '/core/includes/entity.inc'; // Load all enabled modules - module_load_all(); + drupal_container()->get('extension_handler')->loadAll(); // Make sure all stream wrappers are registered. file_get_stream_wrappers(); @@ -6373,7 +6373,7 @@ function drupal_flush_all_caches() { // Ensure that all modules that are currently supposed to be enabled are // actually loaded. - module_load_all(); + drupal_container()->get('extension_handler')->loadAll(); // Update the list of bootstrap modules. // Allows developers to get new hook_boot() implementations registered without diff --git a/core/includes/module.inc b/core/includes/module.inc index f048418..5e2f1b9 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -48,8 +48,8 @@ function system_list($type) { // @see http://drupal.org/node/1067408 $theme_data = state()->get('system.theme.data'); if (empty($theme_data)) { - // @todo: system_list() may be called from _drupal_bootstrap_code() and - // module_load_all(), in which case system.module is not loaded yet. + // @todo: system_list() may be called from _drupal_bootstrap_code(), in + // which case system.module is not loaded yet. // Prevent a filesystem scan in drupal_load() and include it directly. // @see http://drupal.org/node/1067408 require_once DRUPAL_ROOT . '/core/modules/system/system.module'; diff --git a/core/includes/theme.inc b/core/includes/theme.inc index cd7b6b8..181cf97 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -367,14 +367,14 @@ function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL, $registry = _theme_build_registry($theme, $base_theme, $theme_engine); // Only persist this registry if all modules are loaded. This assures a // complete set of theme hooks. - if (module_load_all(NULL)) { + if (drupal_container()->get('extension_handler')->isLoaded()) { _theme_save_registry($theme, $registry); } } return $registry; } else { - return new ThemeRegistry('theme_registry:runtime:' . $theme->name, 'cache', array('theme_registry' => TRUE)); + return new ThemeRegistry('theme_registry:runtime:' . $theme->name, 'cache', array('theme_registry' => TRUE), drupal_container()->get('extension_handler')->isLoaded()); } } @@ -641,7 +641,7 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { _theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module)); } // Only cache this registry if all modules are loaded. - if (module_load_all(NULL)) { + if (drupal_container()->get('extension_handler')->isLoaded()) { cache()->set("theme_registry:build:modules", $cache, CacheBackendInterface::CACHE_PERMANENT, array('theme_registry' => TRUE)); } } @@ -956,7 +956,7 @@ function theme($hook, $variables = array()) { // If called before all modules are loaded, we do not necessarily have a full // theme registry to work with, and therefore cannot process the theme // request properly. See also _theme_load_registry(). - if (!module_load_all(NULL) && !defined('MAINTENANCE_MODE')) { + if (!drupal_container()->get('extension_handler')->isLoaded() && !defined('MAINTENANCE_MODE')) { throw new Exception(t('theme() may not be called until all modules are loaded.')); } diff --git a/core/includes/update.inc b/core/includes/update.inc index 6ad80ef..4b57129 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -92,7 +92,7 @@ function update_prepare_d8_bootstrap() { include_once DRUPAL_ROOT . '/core/includes/install.inc'; include_once DRUPAL_ROOT . '/core/includes/schema.inc'; // Bootstrap to configuration. - drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); + drupal_bootstrap(DRUPAL_BOOTSTRAP_KERNEL); // Check whether settings.php needs to be rewritten. $settings_exist = !empty($GLOBALS['config_directories']); @@ -126,9 +126,10 @@ function update_prepare_d8_bootstrap() { include_once DRUPAL_ROOT . '/core/includes/module.inc'; include_once DRUPAL_ROOT . '/core/includes/cache.inc'; - drupal_container()->get('extension_handler')->setModuleList(array('system' => 'core/modules/system/system.module')); + $extension_handler = drupal_container()->get('extension_handler'); + $extension_handler->setModuleList(array('system' => 'core/modules/system/system.module')); - drupal_container()->get('extension_handler')->load('system'); + $extension_handler->load('system'); // Ensure the configuration directories exist and are writable, or create // them. If the directories have not been specified in settings.php and // created manually already, and either directory cannot be created by the diff --git a/core/lib/Drupal/Core/ExtensionHandler.php b/core/lib/Drupal/Core/ExtensionHandler.php index 488de28..dd74b3f 100644 --- a/core/lib/Drupal/Core/ExtensionHandler.php +++ b/core/lib/Drupal/Core/ExtensionHandler.php @@ -96,19 +96,38 @@ public function load($name) { /** * Implements Drupal\Core\ExtensionHandlerInterface::loadAll(). */ - public function loadAll($bootstrap = FALSE, $reset = FALSE, $loaded = FALSE) { - if ($reset) { - $this->loaded = $loaded; + public function loadAll() { + if (!$this->loaded) { + foreach ($this->moduleList as $module => $filename) { + $this->load($module); + } + $this->loaded = TRUE; } - // Unless $bootstrap is NULL, load the requested set of modules. - if (isset($bootstrap) && !$this->loaded) { - $to_load = $bootstrap ? $this->getBootstrapModules() : array_keys($this->moduleList); - foreach ($to_load as $module) { + } + + /** + * Implements Drupal\Core\ExtensionHandlerInterface::reload(). + */ + public function reloadModules() { + $this->loaded = FALSE; + $this->loadAll(); + } + + /** + * Implements Drupal\Core\ExtensionHandlerInterface::loadBootstrap(). + */ + public function loadBootstrap() { + if (!$this->loaded) { + foreach ($this->getBootstrapModules() as $module) { $this->load($module); } - // $this->loaded will be TRUE if $bootstrap is FALSE. - $this->loaded = !$bootstrap; } + } + + /** + * Implements Drupal\Core\ExtensionHandlerInterface::isLoaded(). + */ + public function isLoaded() { return $this->loaded; } @@ -202,14 +221,14 @@ public function moduleImplements($hook) { // The hook is not cached, so ensure that whether or not it has // implementations, that the cache is updated at the end of the request. $this->implementations['#write_cache'] = TRUE; - $hookInfo = $this->moduleHookInfo(); + $hook_info = $this->moduleHookInfo(); $this->implementations[$hook] = array(); foreach ($this->moduleList as $module => $filename) { - $include_file = isset($hookInfo[$hook]['group']) && module_load_include('inc', $module, $module . '.' . $hookInfo[$hook]['group']); + $include_file = isset($hook_info[$hook]['group']) && module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']); // Since module_hook() may needlessly try to load the include file again, // function_exists() is used directly here. if (function_exists($module . '_' . $hook)) { - $this->implementations[$hook][$module] = $include_file ? $hookInfo[$hook]['group'] : FALSE; + $this->implementations[$hook][$module] = $include_file ? $hook_info[$hook]['group'] : FALSE; } } // Allow modules to change the weight of specific implementations but avoid @@ -238,14 +257,13 @@ public function moduleImplements($hook) { } } } - return array_keys($this->implementations[$hook]); } /** - * Implements Drupal\Core\ExtensionHandlerInterface::cachedHookImplementations(). + * Implements Drupal\Core\ExtensionHandlerInterface::getHookImplementations(). */ - public function cachedHookImplementations() { + public function getHookImplementations() { if (empty($this->implementations)) { return array(); } @@ -282,10 +300,9 @@ public function moduleHookInfo() { // hook_hookInfo() result, so instead return an empty array. This requires // bootstrap hook implementations to reside in the .module file, which is // optimal for performance anyway. - if (!$this->loadAll(NULL)) { + if (!$this->loaded) { return array(); } - if (!isset($this->hookInfo)) { $this->hookInfo = array(); $cache = $this->bootstrapCache->get('hook_info'); @@ -297,6 +314,7 @@ public function moduleHookInfo() { $function = $module . '_hook_info'; if (function_exists($function)) { $result = $function(); + if (isset($result) && is_array($result)) { $this->hookInfo = array_merge_recursive($this->hookInfo, $result); } diff --git a/core/lib/Drupal/Core/ExtensionHandlerInterface.php b/core/lib/Drupal/Core/ExtensionHandlerInterface.php index 56076a1..670fcef 100644 --- a/core/lib/Drupal/Core/ExtensionHandlerInterface.php +++ b/core/lib/Drupal/Core/ExtensionHandlerInterface.php @@ -24,23 +24,22 @@ public function load($name); /** * Loads all the modules that have been enabled. - * - * @param bool $bootstrap - * Whether to load only the reduced set of modules loaded in "bootstrap mode" - * for cached pages. See bootstrap.inc. - * - * @param bool $reset - * (optional) Internal use only. Whether to reset the internal flag of - * whether modules have been loaded. If TRUE, all modules are (re)loaded in - * the same call. Used by the testing framework to override and persist a - * limited module list for the duration of a unit test (in which no module - * system exists). + */ + public function loadAll(); + + /** + * Loads all bootstrap modules. + */ + public function loadBootstrap(); + + /** + * Returns whether all modules have been loaded. * * @return bool * A Boolean indicating whether all modules have been loaded. This means all * modules; the load status of bootstrap modules cannot be checked. */ - public function loadAll($bootstrap = FALSE, $reset = FALSE); + public function isLoaded(); /** * Returns a list of currently active modules. @@ -130,7 +129,7 @@ public function moduleImplementsReset(); /** * Returns the hook implementation cache. */ - public function cachedHookImplementations(); + public function getHookImplementations(); /** * Retrieves a list of hooks that are declared through hook_hook_info(). diff --git a/core/lib/Drupal/Core/ExtensionHandlerMinimal.php b/core/lib/Drupal/Core/ExtensionHandlerMinimal.php index 4718f46..f62ae23 100644 --- a/core/lib/Drupal/Core/ExtensionHandlerMinimal.php +++ b/core/lib/Drupal/Core/ExtensionHandlerMinimal.php @@ -105,7 +105,7 @@ public function moduleHookInfo() { // hook_hook_info() result, so instead return an empty array. This requires // bootstrap hook implementations to reside in the .module file, which is // optimal for performance anyway. - if (!$this->loadAll(NULL)) { + if (!$this->loaded) { return array(); } diff --git a/core/lib/Drupal/Core/Utility/ThemeRegistry.php b/core/lib/Drupal/Core/Utility/ThemeRegistry.php index bc9691c..eb2dd80 100644 --- a/core/lib/Drupal/Core/Utility/ThemeRegistry.php +++ b/core/lib/Drupal/Core/Utility/ThemeRegistry.php @@ -42,12 +42,14 @@ class ThemeRegistry extends CacheArray { * The bin to cache the array. * @param array $tags * (optional) The tags to specify for the cache item. + * @param bool $modules_loaded + * Whether all modules have already been loaded. */ - function __construct($cid, $bin, $tags) { + function __construct($cid, $bin, $tags, $modules_loaded = FALSE) { $this->cid = $cid; $this->bin = $bin; $this->tags = $tags; - $this->persistable = module_load_all(NULL) && $_SERVER['REQUEST_METHOD'] == 'GET'; + $this->persistable = $modules_loaded && $_SERVER['REQUEST_METHOD'] == 'GET'; $data = array(); if ($this->persistable && $cached = cache($this->bin)->get($this->cid)) { diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index c806f43..96856ec 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -223,7 +223,7 @@ protected function enableModules(array $modules, $install = TRUE) { $this->container->get('extension_handler')->setModuleList($enabled); } $this->container->get('extension_handler')->moduleImplementsReset(); - $this->container->get('extension_handler')->loadAll(FALSE, TRUE); + $this->container->get('extension_handler')->reloadModules(); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php index 35faa3c..c60d5eb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php @@ -51,7 +51,7 @@ function testBundleRegistrationDynamic() { $this->assertFalse(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service does not exist in the DIC.'); // Enable the module and ensure the bundle's service is registered. - module_enable(array('bundle_test')); + module_enable(array('bundle_test'), FALSE); $this->assertTrue(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service exists in the DIC.'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php index 8fa84fe..63edb99 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php @@ -36,7 +36,7 @@ function testEnableWithoutDependency() { $this->drupalPost(NULL, NULL, t('Continue')); $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.'); - + $this->rebuildContainer(); $this->assertModules(array('translation_entity', 'language'), TRUE); // Assert that the language tables were enabled. @@ -65,6 +65,7 @@ function testMissingModules() { // Confirm. $this->drupalPost(NULL, NULL, t('Continue')); + $this->rebuildContainer(); // Verify that the module has been disabled. $this->assertModules(array('system_dependencies_test'), FALSE); } @@ -154,6 +155,7 @@ function testModuleEnableOrder() { $edit['modules[Core][poll][enable]'] = 'poll'; $edit['modules[Core][php][enable]'] = 'php'; $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->rebuildContainer(); $this->assertModules(array('forum', 'poll', 'php', 'comment', 'history', 'taxonomy', 'options'), TRUE); // Check the actual order which is saved by module_test_modules_enabled(). @@ -169,14 +171,17 @@ function testUninstallDependents() { $edit = array('modules[Core][forum][enable]' => 'forum'); $this->drupalPost('admin/modules', $edit, t('Save configuration')); $this->drupalPost(NULL, array(), t('Continue')); + $this->rebuildContainer(); $this->assertModules(array('forum'), TRUE); // Disable forum and comment. Both should now be installed but disabled. $edit = array('modules[Core][forum][enable]' => FALSE); $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->rebuildContainer(); $this->assertModules(array('forum'), FALSE); $edit = array('modules[Core][comment][enable]' => FALSE); $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->rebuildContainer(); $this->assertModules(array('comment'), FALSE); // Check that the taxonomy module cannot be uninstalled. 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 d130a7f..b5f6e43 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php @@ -76,6 +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')->getModuleList()); + $enabled_modules = sort($enabled_modules); $this->assertEqual($expected_values, $enabled_modules, format_string('@condition: extension handler returns correct results', array('@condition' => $condition))); } @@ -100,11 +101,12 @@ function testModuleImplements() { // already loaded when the cache is rebuilt. // For that activate the module_test which provides the file to load. module_enable(array('module_test')); - + $extension_handler = drupal_container()->get('extension_handler'); + $extension_handler->loadAll(); module_load_include('inc', 'module_test', 'module_test.file'); - $modules = module_implements('test_hook'); + $modules = $extension_handler->moduleImplements('test_hook'); $this->assertTrue(in_array('module_test', $modules), 'Hook found.'); - $module_implementations = drupal_container()->get('extension_handler')->cachedHookImplementations(); + $module_implementations = $extension_handler->getHookImplementations(); $this->assertEqual($module_implementations['test_hook']['module_test'], 'file', 'Include file detected.'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php index 06f28c2..09f2b50 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php @@ -266,7 +266,7 @@ protected function performUpgrade($register_errors = TRUE) { // Reload module list for modules that are enabled in the test database // but not on the test client. drupal_container()->get('extension_handler')->moduleImplementsReset(); - module_load_all(FALSE, TRUE); + drupal_container()->get('extension_handler')->reloadModules(); // Rebuild the container and all caches. $this->rebuildContainer();