diff --git a/core/core.services.yml b/core/core.services.yml index 3f68677..0545756 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -521,7 +521,7 @@ services: class: Drupal\Core\Extension\RequiredModuleUninstallValidator tags: - { name: module_install.uninstall_validator } - arguments: ['@string_translation'] + arguments: ['@string_translation', '@extension.list.module'] lazy: true theme_handler: class: Drupal\Core\Extension\ThemeHandler @@ -1223,7 +1223,7 @@ services: class: Drupal\Core\EventSubscriber\ConfigImportSubscriber tags: - { name: event_subscriber } - arguments: ['@theme_handler'] + arguments: ['@extension.list.module', '@theme_handler'] config_snapshot_subscriber: class: Drupal\Core\EventSubscriber\ConfigSnapshotSubscriber tags: diff --git a/core/includes/common.inc b/core/includes/common.inc index 53e0be5..7420d02 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1120,7 +1120,7 @@ function drupal_flush_all_caches() { PhpStorageFactory::get('twig')->deleteAll(); // Rebuild module and theme data. - $module_data = system_rebuild_module_data(); + $module_data = \Drupal::service('extension.list.module')->reset()->getList(); /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */ $theme_handler = \Drupal::service('theme_handler'); $theme_handler->refreshInfo(); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index b4c731d..3fcb423 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1501,7 +1501,7 @@ function install_profile_modules(&$install_state) { install_core_entity_type_definitions(); $modules = \Drupal::state()->get('install_profile_modules') ?: []; - $files = system_rebuild_module_data(); + $files = \Drupal::service('extension.list.module')->getList(); \Drupal::state()->delete('install_profile_modules'); // Always install required modules first. Respect the dependencies between diff --git a/core/includes/update.inc b/core/includes/update.inc index d7fe942..7e5eb99 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -43,7 +43,7 @@ function update_check_incompatibility($name, $type = 'module') { // code changes that were made in the filesystem before the update script // was initiated. $themes = \Drupal::service('theme_handler')->rebuildThemeData(); - $modules = system_rebuild_module_data(); + $modules = \Drupal::service('extension.list.module')->reset()->getList(); } if ($type == 'module' && isset($modules[$name])) { diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index b58f963..dcaee49 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Config; use Drupal\Core\Config\Importer\MissingContentEvent; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -159,6 +160,13 @@ class ConfigImporter { protected $moduleInstaller; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * Constructs a configuration import object. * * @param \Drupal\Core\Config\StorageComparerInterface $storage_comparer @@ -180,8 +188,13 @@ class ConfigImporter { * The theme handler * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. + * @param \Drupal\Core\Extension\ModuleExtensionList|null $extension_list_module + * (optional) The module extension list */ - public function __construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation) { + public function __construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation, ModuleExtensionList $extension_list_module = NULL) { + if ($extension_list_module === NULL) { + @trigger_error('Invoking the ConfigImporter constructor without the module extension list parameter is deprecated in Drupal 8.6.0 and will no longer be supported in Drupal 9.0.0. The extension list parameter is now required in the ConfigImporter constructor.', E_USER_DEPRECATED); + } $this->storageComparer = $storage_comparer; $this->eventDispatcher = $event_dispatcher; $this->configManager = $config_manager; @@ -191,6 +204,7 @@ public function __construct(StorageComparerInterface $storage_comparer, EventDis $this->moduleInstaller = $module_installer; $this->themeHandler = $theme_handler; $this->stringTranslation = $string_translation; + $this->moduleExtensionList = $extension_list_module; foreach ($this->storageComparer->getAllCollectionNames() as $collection) { $this->processedConfiguration[$collection] = $this->storageComparer->getEmptyChangelist(); } @@ -369,7 +383,7 @@ protected function createExtensionChangelist() { } // Get a list of modules with dependency weights as values. - $module_data = system_rebuild_module_data(); + $module_data = $this->getModuleExtensionList()->getList(); // Set the actual module weights. $module_list = array_combine(array_keys($module_data), array_keys($module_data)); $module_list = array_map(function ($module) use ($module_data) { @@ -1045,4 +1059,16 @@ protected function reInjectMe() { } } + /** + * Gets the module extension list. + * + * @return \Drupal\Core\Extension\ModuleExtensionList + */ + protected function getModuleExtensionList() { + if ($this->moduleExtensionList === null) { + $this->moduleExtensionList = \Drupal::service('extension.list.module'); + } + return $this->moduleExtensionList; + } + } diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php index ea7d29f..7403715 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigImporterEvent; use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase; use Drupal\Core\Config\ConfigNameException; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ThemeHandlerInterface; /** @@ -22,11 +23,11 @@ class ConfigImportSubscriber extends ConfigImportValidateEventSubscriberBase { protected $themeData; /** - * Module data. + * Module extension list. * - * @var \Drupal\Core\Extension\Extension[] + * @var \Drupal\Core\Extension\ModuleExtensionList */ - protected $moduleData; + protected $moduleExtensionList; /** * The theme handler. @@ -38,10 +39,13 @@ class ConfigImportSubscriber extends ConfigImportValidateEventSubscriberBase { /** * Constructs the ConfigImportSubscriber. * + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. */ - public function __construct(ThemeHandlerInterface $theme_handler) { + public function __construct(ModuleExtensionList $extension_list_module, ThemeHandlerInterface $theme_handler) { + $this->moduleExtensionList = $extension_list_module; $this->themeHandler = $theme_handler; } @@ -85,7 +89,7 @@ public function onConfigImporterValidate(ConfigImporterEvent $event) { protected function validateModules(ConfigImporter $config_importer) { $core_extension = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension'); // Get a list of modules with dependency weights as values. - $module_data = $this->getModuleData(); + $module_data = $this->moduleExtensionList->getList(); $nonexistent_modules = array_keys(array_diff_key($core_extension['module'], $module_data)); foreach ($nonexistent_modules as $module) { $config_importer->logError($this->t('Unable to install the %module module since it does not exist.', ['%module' => $module])); @@ -200,7 +204,7 @@ protected function validateDependencies(ConfigImporter $config_importer) { ]; $theme_data = $this->getThemeData(); - $module_data = $this->getModuleData(); + $module_data = $this->moduleExtensionList->getList(); // Validate the dependencies of all the configuration. We have to validate // the entire tree because existing configuration might depend on @@ -297,18 +301,6 @@ protected function getThemeData() { } /** - * Gets module data. - * - * @return \Drupal\Core\Extension\Extension[] - */ - protected function getModuleData() { - if (!isset($this->moduleData)) { - $this->moduleData = system_rebuild_module_data(); - } - return $this->moduleData; - } - - /** * Gets human readable extension names. * * @param array $names diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 2cf34bd..8947151 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -83,7 +83,9 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $extension_config = \Drupal::configFactory()->getEditable('core.extension'); if ($enable_dependencies) { // Get all module data so we can find dependencies and sort. - $module_data = system_rebuild_module_data(); + // The module list needs to be reset so that it can re-scan and include + // any new modules that may have been added directly into the filesystem. + $module_data = \Drupal::service('extension.list.module')->reset()->getList(); $module_list = $module_list ? array_combine($module_list, $module_list) : []; if ($missing_modules = array_diff_key($module_list, $module_data)) { // One or more of the given modules doesn't exist. @@ -329,7 +331,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { */ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // Get all module data so we can find dependencies and sort. - $module_data = system_rebuild_module_data(); + $module_data = \Drupal::service('extension.list.module')->getList(); $module_list = $module_list ? array_combine($module_list, $module_list) : []; if (array_diff_key($module_list, $module_data)) { // One or more of the given modules doesn't exist. diff --git a/core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php b/core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php index d3fa533..6c01c42 100644 --- a/core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php +++ b/core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php @@ -13,13 +13,21 @@ class RequiredModuleUninstallValidator implements ModuleUninstallValidatorInterf use StringTranslationTrait; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * Constructs a new RequiredModuleUninstallValidator. * * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. */ - public function __construct(TranslationInterface $string_translation) { + public function __construct(TranslationInterface $string_translation, ModuleExtensionList $extension_list_module) { $this->stringTranslation = $string_translation; + $this->moduleExtensionList = $extension_list_module; } /** @@ -41,11 +49,17 @@ public function validate($module) { * The name of the module. * * @return array - * The module info, or NULL if that module does not exist. + * The module info, or empty array if that module does not exist. */ protected function getModuleInfoByModule($module) { - $modules = system_rebuild_module_data(); - return isset($modules[$module]->info) ? $modules[$module]->info : []; + try { + return $this->moduleExtensionList->get($module)->info; + } + catch (\InvalidArgumentException $e) { + // @todo Replace with dedicated exception + // https://www.drupal.org/project/drupal/issues/2940203 + return []; + } } } diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index 45355cc..e39c341 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -131,7 +131,7 @@ function hook_module_implements_alter(&$implementations, $hook) { /** * Alter the information parsed from module and theme .info.yml files. * - * This hook is invoked in _system_rebuild_module_data() and in + * This hook is invoked in \Drupal\Core\Extension\ExtensionList::getList() and in * \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData(). A module * may implement this hook in order to add to or alter the data generated by * reading the .info.yml file with \Drupal\Core\Extension\InfoParser. diff --git a/core/modules/book/tests/src/Kernel/BookUninstallTest.php b/core/modules/book/tests/src/Kernel/BookUninstallTest.php index d4205eb..13cbb42 100644 --- a/core/modules/book/tests/src/Kernel/BookUninstallTest.php +++ b/core/modules/book/tests/src/Kernel/BookUninstallTest.php @@ -76,7 +76,7 @@ public function testBookUninstall() { $book_node->delete(); // No nodes exist therefore the book module is not required. - $module_data = \Drupal::service('extension.list.module')->reset()->getList(); + $module_data = \Drupal::service('extension.list.module')->getList(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); $node = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php index 9f9a8d9..3db18ea 100644 --- a/core/modules/config/src/Form/ConfigSingleImportForm.php +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -95,6 +96,13 @@ class ConfigSingleImportForm extends ConfirmFormBase { protected $themeHandler; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * The module installer. * * @var \Drupal\Core\Extension\ModuleInstallerInterface @@ -138,8 +146,10 @@ class ConfigSingleImportForm extends ConfirmFormBase { * The module installer. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list */ - public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage, RendererInterface $renderer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler) { + public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage, RendererInterface $renderer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, ModuleExtensionList $extension_list_module) { $this->entityManager = $entity_manager; $this->configStorage = $config_storage; $this->renderer = $renderer; @@ -152,6 +162,7 @@ public function __construct(EntityManagerInterface $entity_manager, StorageInter $this->moduleHandler = $module_handler; $this->moduleInstaller = $module_installer; $this->themeHandler = $theme_handler; + $this->moduleExtensionList = $extension_list_module; } /** @@ -168,7 +179,8 @@ public static function create(ContainerInterface $container) { $container->get('config.typed'), $container->get('module_handler'), $container->get('module_installer'), - $container->get('theme_handler') + $container->get('theme_handler'), + $container->get('extension.list.module') ); } @@ -358,7 +370,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $this->moduleHandler, $this->moduleInstaller, $this->themeHandler, - $this->getStringTranslation() + $this->getStringTranslation(), + $this->moduleExtensionList ); try { diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php index 2813099..4232b2b 100644 --- a/core/modules/config/src/Form/ConfigSync.php +++ b/core/modules/config/src/Form/ConfigSync.php @@ -5,6 +5,7 @@ use Drupal\Core\Config\ConfigImporterException; use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\TypedConfigManagerInterface; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -104,6 +105,13 @@ class ConfigSync extends FormBase { protected $renderer; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * Constructs the object. * * @param \Drupal\Core\Config\StorageInterface $sync_storage @@ -128,8 +136,10 @@ class ConfigSync extends FormBase { * The theme handler. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list */ - public function __construct(StorageInterface $sync_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, RendererInterface $renderer) { + public function __construct(StorageInterface $sync_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, RendererInterface $renderer, ModuleExtensionList $extension_list_module) { $this->syncStorage = $sync_storage; $this->activeStorage = $active_storage; $this->snapshotStorage = $snapshot_storage; @@ -141,6 +151,7 @@ public function __construct(StorageInterface $sync_storage, StorageInterface $ac $this->moduleInstaller = $module_installer; $this->themeHandler = $theme_handler; $this->renderer = $renderer; + $this->moduleExtensionList = $extension_list_module; } /** @@ -158,7 +169,8 @@ public static function create(ContainerInterface $container) { $container->get('module_handler'), $container->get('module_installer'), $container->get('theme_handler'), - $container->get('renderer') + $container->get('renderer'), + $container->get('extension.list.module') ); } @@ -327,7 +339,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->moduleHandler, $this->moduleInstaller, $this->themeHandler, - $this->getStringTranslation() + $this->getStringTranslation(), + $this->moduleExtensionList ); if ($config_importer->alreadyImporting()) { drupal_set_message($this->t('Another request may be synchronizing configuration already.')); diff --git a/core/modules/config/tests/src/Functional/ConfigImportAllTest.php b/core/modules/config/tests/src/Functional/ConfigImportAllTest.php index 4823e6b..549dbf7 100644 --- a/core/modules/config/tests/src/Functional/ConfigImportAllTest.php +++ b/core/modules/config/tests/src/Functional/ConfigImportAllTest.php @@ -47,7 +47,7 @@ protected function setUp() { public function testInstallUninstall() { // Get a list of modules to enable. - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList(); $all_modules = array_filter($all_modules, function ($module) { // Filter contrib, hidden, already enabled modules and modules in the // Testing package. @@ -93,8 +93,7 @@ public function testInstallUninstall() { $shortcuts = Shortcut::loadMultiple(); entity_delete_multiple('shortcut', array_keys($shortcuts)); - system_list_reset(); - $all_modules = system_rebuild_module_data(); + $all_modules = \Drupal::service('extension.list.module')->getList(); // Ensure that only core required modules and the install profile can not be uninstalled. $validation_reasons = \Drupal::service('module_installer')->validateUninstall(array_keys($all_modules)); diff --git a/core/modules/config/tests/src/Functional/ConfigImportUITest.php b/core/modules/config/tests/src/Functional/ConfigImportUITest.php index fd76990..a6ce280 100644 --- a/core/modules/config/tests/src/Functional/ConfigImportUITest.php +++ b/core/modules/config/tests/src/Functional/ConfigImportUITest.php @@ -498,7 +498,7 @@ public function testExtensionValidation() { $core = $sync->read('core.extension'); // Node depends on text. unset($core['module']['text']); - $module_data = system_rebuild_module_data(); + $module_data = $this->container->get('extension.list.module')->getList(); $this->assertTrue(isset($module_data['node']->requires['text']), 'The Node module depends on the Text module.'); // Bartik depends on classy. unset($core['theme']['classy']); diff --git a/core/modules/content_translation/tests/src/Kernel/ContentTranslationConfigImportTest.php b/core/modules/content_translation/tests/src/Kernel/ContentTranslationConfigImportTest.php index b8776a2..78b4de6 100644 --- a/core/modules/content_translation/tests/src/Kernel/ContentTranslationConfigImportTest.php +++ b/core/modules/content_translation/tests/src/Kernel/ContentTranslationConfigImportTest.php @@ -51,7 +51,8 @@ protected function setUp() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); } diff --git a/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php b/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php index afd468a..a4a0f10 100644 --- a/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php +++ b/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php @@ -197,7 +197,7 @@ protected function checkDisplayOption($entity_type_id, $field_id, BaseFieldDefin * and all modules required by any of these modules. */ protected function modulesWithSubdirectory($subdirectory) { - $modules = system_rebuild_module_data(); + $modules = $this->container->get('extension.list.module')->getList(); $modules = array_filter($modules, function (Extension $module) use ($subdirectory) { // Filter contrib, hidden, already enabled modules and modules in the // Testing package. diff --git a/core/modules/filter/tests/src/Functional/FilterFormTest.php b/core/modules/filter/tests/src/Functional/FilterFormTest.php index d5b6f98..161f5d6 100644 --- a/core/modules/filter/tests/src/Functional/FilterFormTest.php +++ b/core/modules/filter/tests/src/Functional/FilterFormTest.php @@ -71,8 +71,6 @@ public function testFilterForm() { // correctly. // @see https://www.drupal.org/node/2387983 \Drupal::service('module_installer')->install(['filter_test_plugin']); - // Force rebuild module data. - \Drupal::service('extension.list.module')->reset(); } /** diff --git a/core/modules/filter/tests/src/Kernel/FilterAPITest.php b/core/modules/filter/tests/src/Kernel/FilterAPITest.php index d5ab649..5533105 100644 --- a/core/modules/filter/tests/src/Kernel/FilterAPITest.php +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php @@ -488,7 +488,7 @@ public function testDependencyRemoval() { drupal_static_reset('filter_formats'); \Drupal::entityManager()->getStorage('filter_format')->resetCache(); - $module_data = \Drupal::service('extension.list.module')->reset()->getList(); + $module_data = \Drupal::service('extension.list.module')->getList(); $this->assertFalse(isset($module_data['filter_test']->info['required']), 'The filter_test module is required.'); // Verify that a dependency exists on the module that provides the filter diff --git a/core/modules/help/tests/src/Functional/HelpTest.php b/core/modules/help/tests/src/Functional/HelpTest.php index dff11ef..0946ac6 100644 --- a/core/modules/help/tests/src/Functional/HelpTest.php +++ b/core/modules/help/tests/src/Functional/HelpTest.php @@ -152,7 +152,7 @@ protected function verifyHelp($response = 200) { */ protected function getModuleList() { $modules = []; - $module_data = system_rebuild_module_data(); + $module_data = $this->container->get('extension.list.module')->getList(); foreach (\Drupal::moduleHandler()->getImplementations('help') as $module) { $modules[$module] = $module_data[$module]->info['name']; } diff --git a/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php b/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php index 070a954..61e1a7c 100644 --- a/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php +++ b/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php @@ -32,7 +32,7 @@ public function register(ContainerBuilder $container) { * Ensures that no URL generator is called on a page without hook_help(). */ public function testEmptyHookHelp() { - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList();; $all_modules = array_filter($all_modules, function ($module) { // Filter contrib, hidden, already enabled modules and modules in the // Testing package. diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index c66af14..1c42b7e 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -103,7 +103,7 @@ function locale_translation_project_list() { 'interface translation project', 'interface translation server pattern', ]; - $module_data = _locale_translation_prepare_project_list(system_rebuild_module_data(), 'module'); + $module_data = _locale_translation_prepare_project_list(\Drupal::service('extension.list.module')->getList(), 'module'); $theme_data = _locale_translation_prepare_project_list(\Drupal::service('theme_handler')->rebuildThemeData(), 'theme'); $project_info = new ProjectInfo(); $project_info->processInfoList($projects, $module_data, 'module', TRUE, $additional_whitelist); diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php index 6421472..98b0de7 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php @@ -29,7 +29,7 @@ class EntityResourceRestTestCoverageTest extends BrowserTestBase { protected function setUp() { parent::setUp(); - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList();; $stable_core_modules = array_filter($all_modules, function ($module) { // Filter out contrib, hidden, testing, and experimental modules. We also // don't need to enable modules that are already enabled. diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 3ff6c3d..96e2db5 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\UnmetDependenciesException; use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Extension\Extension; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\FormBase; @@ -66,12 +67,20 @@ class ModulesListForm extends FormBase { protected $permissionHandler; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('module_handler'), $container->get('module_installer'), + $container->get('extension.list.module'), $container->get('keyvalue.expirable')->get('module_list'), $container->get('access_manager'), $container->get('current_user'), @@ -86,6 +95,8 @@ public static function create(ContainerInterface $container) { * The module handler. * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer * The module installer. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list. * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable * The key value expirable factory. * @param \Drupal\Core\Access\AccessManagerInterface $access_manager @@ -95,9 +106,10 @@ public static function create(ContainerInterface $container) { * @param \Drupal\user\PermissionHandlerInterface $permission_handler * The permission handler. */ - public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, AccountInterface $current_user, PermissionHandlerInterface $permission_handler) { + public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ModuleExtensionList $extension_list_module, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, AccountInterface $current_user, PermissionHandlerInterface $permission_handler) { $this->moduleHandler = $module_handler; $this->moduleInstaller = $module_installer; + $this->moduleExtensionList = $extension_list_module; $this->keyValueExpirable = $key_value_expirable; $this->accessManager = $access_manager; $this->currentUser = $current_user; @@ -143,7 +155,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; // Sort all modules by their names. - $modules = system_rebuild_module_data(); + // The module list needs to be reset so that it can re-scan and include any + // new modules that may have been added directly into the filesystem. + $modules = $this->moduleExtensionList->reset()->getList(); uasort($modules, 'system_sort_modules_by_info_name'); // Iterate over each of the modules. @@ -368,7 +382,7 @@ protected function buildModuleList(FormStateInterface $form_state) { 'experimental' => [], ]; - $data = system_rebuild_module_data(); + $data = $this->moduleExtensionList->getList(); foreach ($data as $name => $module) { // If the module is installed there is nothing to do. if ($this->moduleHandler->moduleExists($name)) { diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php index f55f0d6..bdaf1b2 100644 --- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php @@ -5,6 +5,7 @@ use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; @@ -56,6 +57,13 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase { protected $modules = []; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * Constructs a ModulesUninstallConfirmForm object. * * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer @@ -66,12 +74,15 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase { * The configuration manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list */ - public function __construct(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) { + public function __construct(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager, ModuleExtensionList $extension_list_module) { $this->moduleInstaller = $module_installer; $this->keyValueExpirable = $key_value_expirable; $this->configManager = $config_manager; $this->entityManager = $entity_manager; + $this->moduleExtensionList = $extension_list_module; } /** @@ -82,7 +93,8 @@ public static function create(ContainerInterface $container) { $container->get('module_installer'), $container->get('keyvalue.expirable')->get('modules_uninstall'), $container->get('config.manager'), - $container->get('entity.manager') + $container->get('entity.manager'), + $container->get('extension.list.module') ); } @@ -135,7 +147,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { return $this->redirect('system.modules_uninstall'); } - $data = system_rebuild_module_data(); + $data = $this->moduleExtensionList->getList(); $form['text']['#markup'] = '

' . $this->t('The following modules will be completely uninstalled from your site, and all data from these modules will be lost!') . '

'; $form['modules'] = [ '#theme' => 'item_list', diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php index 7949067..bf3a06e 100644 --- a/core/modules/system/src/Form/ModulesUninstallForm.php +++ b/core/modules/system/src/Form/ModulesUninstallForm.php @@ -2,6 +2,7 @@ namespace Drupal\system\Form; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\FormBase; @@ -38,12 +39,20 @@ class ModulesUninstallForm extends FormBase { protected $keyValueExpirable; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('module_handler'), $container->get('module_installer'), + $container->get('extension.list.module'), $container->get('keyvalue.expirable')->get('modules_uninstall') ); } @@ -55,12 +64,15 @@ public static function create(ContainerInterface $container) { * The module handler. * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer * The module installer. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list. * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable * The key value expirable factory. */ - public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable) { + public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ModuleExtensionList $extension_list_module, KeyValueStoreExpirableInterface $key_value_expirable) { $this->moduleHandler = $module_handler; $this->moduleInstaller = $module_installer; + $this->moduleExtensionList = $extension_list_module; $this->keyValueExpirable = $key_value_expirable; } @@ -78,11 +90,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Make sure the install API is available. include_once DRUPAL_ROOT . '/core/includes/install.inc'; - // Get a list of all available modules. - $modules = system_rebuild_module_data(); - $uninstallable = array_filter($modules, function ($module) use ($modules) { - return empty($modules[$module->getName()]->info['required']) && $module->status; - }); + // Get a list of all available modules that can be uninstalled. + $uninstallable = array_filter($this->moduleExtensionList->getList(), + function ($module) { + return empty($module->info['required']) && $module->status; + }); // Include system.admin.inc so we can use the sort callbacks. $this->moduleHandler->loadInclude('system', 'inc', 'system.admin'); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 1838326..6869b5b 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -787,7 +787,7 @@ function system_requirements($phase) { // Display an error if a newly introduced dependency in a module is not resolved. if ($phase == 'update') { $profile = drupal_get_profile(); - $files = system_rebuild_module_data(); + $files = \Drupal::service('extension.list.module')->getList(); foreach ($files as $module => $file) { // Ignore disabled modules and installation profiles. if (!$file->status || $module == $profile) { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index bb82d4b..193aa37 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -955,7 +955,7 @@ function system_check_directory($form_element, FormStateInterface $form_state) { * information for $name, if given. If no records are available, an empty * array is returned. * - * @see system_rebuild_module_data() + * @see \Drupal\Core\Extension\ModuleExtensionList::getList() * @see \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData() */ function system_get_info($type, $name = NULL) { @@ -1040,8 +1040,14 @@ function _system_rebuild_module_data() { * * @return \Drupal\Core\Extension\Extension[] * Array of all available modules and their data. + * + * @deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. + * Use \Drupal::service('extension.list.module')->getList() instead. + * + * @see https://www.drupal.org/node/2709919 */ function system_rebuild_module_data() { + @trigger_error("system_rebuild_module_data() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Instead, you should use \\Drupal::service('extension.list.module')->getList(). See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); return \Drupal::service('extension.list.module')->reset()->getList(); } diff --git a/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php b/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php index 4d8f30d..5b65cb6 100644 --- a/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php +++ b/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php @@ -33,7 +33,7 @@ public function testInstallUninstall() { $this->assertEqual($this->container->get('state')->get('system_test_preuninstall_module'), 'module_test'); $this->resetAll(); - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList(); // Test help on required modules, but do not test uninstalling. $required_modules = array_filter($all_modules, function ($module) { diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index a8767e9..4ebf35a 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -25,14 +25,7 @@ class ModuleHandlerTest extends KernelTestBase { protected function setUp() { parent::setUp(); - // @todo ModuleInstaller calls system_rebuild_module_data which is part of - // system.module, see https://www.drupal.org/node/2208429. - include_once $this->root . '/core/modules/system/system.module'; - - // Set up the state values so we know where to find the files when running - // drupal_get_filename(). - // @todo Remove as part of https://www.drupal.org/node/2186491 - system_rebuild_module_data(); + $this->container->get('extension.list.module')->getList(); } /** @@ -105,7 +98,6 @@ public function testDependencyResolution() { // Color will depend on Config, which depends on a non-existing module Foo. // Nothing should be installed. \Drupal::state()->set('module_test.dependency', 'missing dependency'); - \Drupal::service('extension.list.module')->reset(); try { $result = $this->moduleInstaller()->install(['color']); @@ -120,7 +112,6 @@ public function testDependencyResolution() { // Fix the missing dependency. // Color module depends on Config. Config depends on Help module. \Drupal::state()->set('module_test.dependency', 'dependency'); - \Drupal::service('extension.list.module')->reset(); $result = $this->moduleInstaller()->install(['color']); $this->assertTrue($result, 'ModuleInstaller::install() returns the correct value.'); @@ -152,7 +143,6 @@ public function testDependencyResolution() { // dependency on a specific version of Help module in its info file. Make // sure that Drupal\Core\Extension\ModuleInstaller::install() still works. \Drupal::state()->set('module_test.dependency', 'version dependency'); - \Drupal::service('extension.list.module')->reset(); $result = $this->moduleInstaller()->install(['color']); $this->assertTrue($result, 'ModuleInstaller::install() returns the correct value.'); @@ -182,7 +172,7 @@ public function testUninstallProfileDependency() { drupal_get_filename('profile', $profile, 'core/profiles/' . $profile . '/' . $profile . '.info.yml'); $this->enableModules(['module_test', $profile]); - $data = \Drupal::service('extension.list.module')->reset()->getList(); + $data = \Drupal::service('extension.list.module')->getList(); $this->assertTrue(isset($data[$profile]->requires[$dependency])); $this->moduleInstaller()->install([$dependency]); @@ -220,7 +210,6 @@ public function testUninstallContentDependency() { // entity_test will depend on help. This way help can not be uninstalled // when there is test content preventing entity_test from being uninstalled. \Drupal::state()->set('module_test.dependency', 'dependency'); - \Drupal::service('extension.list.module')->reset(); // Create an entity so that the modules can not be disabled. $entity = EntityTest::create(['name' => $this->randomString()]); @@ -259,7 +248,7 @@ public function testUninstallContentDependency() { */ public function testModuleMetaData() { // Generate the list of available modules. - $modules = system_rebuild_module_data(); + $modules = $this->container->get('extension.list.module')->getList(); // Check that the mtime field exists for the system module. $this->assertTrue(!empty($modules['system']->info['mtime']), 'The system.info.yml file modification time field is present.'); // Use 0 if mtime isn't present, to avoid an array index notice. diff --git a/core/modules/system/tests/src/Kernel/System/InfoAlterTest.php b/core/modules/system/tests/src/Kernel/System/InfoAlterTest.php index ebdac3c..ee5fbf6 100644 --- a/core/modules/system/tests/src/Kernel/System/InfoAlterTest.php +++ b/core/modules/system/tests/src/Kernel/System/InfoAlterTest.php @@ -22,14 +22,14 @@ class InfoAlterTest extends KernelTestBase { */ public function testSystemInfoAlter() { \Drupal::state()->set('module_required_test.hook_system_info_alter', TRUE); - $info = system_rebuild_module_data(); + $info = \Drupal::service('extension.list.module')->getList(); $this->assertFalse(isset($info['node']->info['required']), 'Before the module_required_test is installed the node module is not required.'); // Enable the test module. \Drupal::service('module_installer')->install(['module_required_test'], FALSE); $this->assertTrue(\Drupal::moduleHandler()->moduleExists('module_required_test'), 'Test required module is enabled.'); - $info = system_rebuild_module_data(); + $info = \Drupal::service('extension.list.module')->getList(); $this->assertTrue($info['node']->info['required'], 'After the module_required_test is installed the node module is required.'); } diff --git a/core/modules/update/src/UpdateManager.php b/core/modules/update/src/UpdateManager.php index 0741691..2c5cfe8 100644 --- a/core/modules/update/src/UpdateManager.php +++ b/core/modules/update/src/UpdateManager.php @@ -4,6 +4,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; @@ -68,6 +69,13 @@ class UpdateManager implements UpdateManagerInterface { protected $themeHandler; /** + * The module extension list. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleExtensionList; + + /** * Constructs a UpdateManager. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -82,8 +90,10 @@ class UpdateManager implements UpdateManagerInterface { * The expirable key/value factory. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, UpdateProcessorInterface $update_processor, TranslationInterface $translation, KeyValueFactoryInterface $key_value_expirable_factory, ThemeHandlerInterface $theme_handler) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, UpdateProcessorInterface $update_processor, TranslationInterface $translation, KeyValueFactoryInterface $key_value_expirable_factory, ThemeHandlerInterface $theme_handler, ModuleExtensionList $extension_list_module) { $this->updateSettings = $config_factory->get('update.settings'); $this->moduleHandler = $module_handler; $this->updateProcessor = $update_processor; @@ -92,6 +102,7 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle $this->themeHandler = $theme_handler; $this->availableReleasesTempStore = $key_value_expirable_factory->get('update_available_releases'); $this->projects = []; + $this->moduleExtensionList = $extension_list_module; } /** @@ -129,7 +140,7 @@ public function getProjects() { $this->projects = $this->projectStorage('update_project_projects'); if (empty($this->projects)) { // Still empty, so we have to rebuild. - $module_data = system_rebuild_module_data(); + $module_data = $this->moduleExtensionList->reset()->getList(); $theme_data = $this->themeHandler->rebuildThemeData(); $project_info = new ProjectInfo(); $project_info->processInfoList($this->projects, $module_data, 'module', TRUE); diff --git a/core/modules/update/tests/src/Functional/UpdateContribTest.php b/core/modules/update/tests/src/Functional/UpdateContribTest.php index 20d397c..343a157 100644 --- a/core/modules/update/tests/src/Functional/UpdateContribTest.php +++ b/core/modules/update/tests/src/Functional/UpdateContribTest.php @@ -120,7 +120,7 @@ public function testUpdateContribBasic() { * project. We need to make sure that we see the "BBB" project before the * "CCC" project, even though "CCC" includes a module that's processed first * if you sort alphabetically by module name (which is the order we see things - * inside system_rebuild_module_data() for example). + * inside \Drupal\Core\Extension\ExtensionList::getList() for example). */ public function testUpdateContribOrder() { // We want core to be version 8.0.0. diff --git a/core/modules/update/update.services.yml b/core/modules/update/update.services.yml index fc176d6..767a1d1 100644 --- a/core/modules/update/update.services.yml +++ b/core/modules/update/update.services.yml @@ -6,7 +6,7 @@ services: - { name: access_check, applies_to: _access_update_manager } update.manager: class: Drupal\update\UpdateManager - arguments: ['@config.factory', '@module_handler', '@update.processor', '@string_translation', '@keyvalue.expirable', '@theme_handler'] + arguments: ['@config.factory', '@module_handler', '@update.processor', '@string_translation', '@keyvalue.expirable', '@theme_handler', '@extension.list.module'] update.processor: class: Drupal\update\UpdateProcessor arguments: ['@config.factory', '@queue', '@update.fetcher', '@state', '@private_key', '@keyvalue', '@keyvalue.expirable'] diff --git a/core/modules/user/src/PermissionHandler.php b/core/modules/user/src/PermissionHandler.php index 1f07b25..056c435 100644 --- a/core/modules/user/src/PermissionHandler.php +++ b/core/modules/user/src/PermissionHandler.php @@ -229,13 +229,4 @@ protected function getModuleNames() { return $modules; } - /** - * Wraps system_rebuild_module_data() - * - * @return \Drupal\Core\Extension\Extension[] - */ - protected function systemRebuildModuleData() { - return system_rebuild_module_data(); - } - } diff --git a/core/modules/user/tests/src/Unit/PermissionHandlerTest.php b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php index 2918d2f..94791ce 100644 --- a/core/modules/user/tests/src/Unit/PermissionHandlerTest.php +++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php @@ -29,7 +29,7 @@ class PermissionHandlerTest extends UnitTestCase { /** * The tested permission handler. * - * @var \Drupal\Tests\user\Unit\TestPermissionHandler|\Drupal\user\PermissionHandler + * @var \Drupal\user\PermissionHandler */ protected $permissionHandler; @@ -142,10 +142,7 @@ public function testBuildPermissionsYaml() { $this->controllerResolver->expects($this->never()) ->method('getControllerFromDefinition'); - $this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); - - // Setup system_rebuild_module_data(). - $this->permissionHandler->setSystemRebuildModuleData($extensions); + $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); $actual_permissions = $this->permissionHandler->getPermissions(); $this->assertPermissions($actual_permissions); @@ -206,7 +203,7 @@ public function testBuildPermissionsSortPerModule() { ->method('getModuleList') ->willReturn(array_flip($modules)); - $permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); + $permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); $actual_permissions = $permissionHandler->getPermissions(); $this->assertEquals(['access_module_a4', 'access_module_a1', 'access_module_a2', 'access_module_a3'], array_keys($actual_permissions)); @@ -287,10 +284,7 @@ public function testBuildPermissionsYamlCallback() { ->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescriptionRestrictAccess') ->willReturn([new TestPermissionCallbacks(), 'titleDescriptionRestrictAccess']); - $this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); - - // Setup system_rebuild_module_data(). - $this->permissionHandler->setSystemRebuildModuleData($extensions); + $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); $actual_permissions = $this->permissionHandler->getPermissions(); $this->assertPermissions($actual_permissions); @@ -341,10 +335,7 @@ public function testPermissionsYamlStaticAndCallback() { ->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription') ->willReturn([new TestPermissionCallbacks(), 'titleDescription']); - $this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); - - // Setup system_rebuild_module_data(). - $this->permissionHandler->setSystemRebuildModuleData($extensions); + $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver); $actual_permissions = $this->permissionHandler->getPermissions(); @@ -377,25 +368,6 @@ protected function assertPermissions(array $actual_permissions) { } -class TestPermissionHandler extends PermissionHandler { - - /** - * Test module data. - * - * @var array - */ - protected $systemModuleData; - - protected function systemRebuildModuleData() { - return $this->systemModuleData; - } - - public function setSystemRebuildModuleData(array $extensions) { - $this->systemModuleData = $extensions; - } - -} - class TestPermissionCallbacks { public function singleDescription() { diff --git a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php index 39a5acc..4f987f2 100644 --- a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php +++ b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php @@ -45,22 +45,6 @@ class DefaultConfigTest extends KernelTestBase { ]; /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - // @todo ModuleInstaller calls system_rebuild_module_data which is part of - // system.module, see https://www.drupal.org/node/2208429. - include_once $this->root . '/core/modules/system/system.module'; - - // Set up the state values so we know where to find the files when running - // drupal_get_filename(). - // @todo Remove as part of https://www.drupal.org/node/2186491 - system_rebuild_module_data(); - } - - /** * Tests if installed config is equal to the exported config. * * @dataProvider coreModuleListDataProvider diff --git a/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php b/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php index 2131a35..b1ff3db 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php @@ -99,7 +99,7 @@ protected function setUp() { $this->container->get('theme_installer')->install($this->allThemes); // Enable all core modules. - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList(); $all_modules = array_filter($all_modules, function ($module) { // Filter contrib, hidden, already enabled modules and modules in the // Testing package. diff --git a/core/tests/Drupal/KernelTests/Core/Bootstrap/GetFilenameTest.php b/core/tests/Drupal/KernelTests/Core/Bootstrap/GetFilenameTest.php index 396facf..48a0316 100644 --- a/core/tests/Drupal/KernelTests/Core/Bootstrap/GetFilenameTest.php +++ b/core/tests/Drupal/KernelTests/Core/Bootstrap/GetFilenameTest.php @@ -30,11 +30,6 @@ public function register(ContainerBuilder $container) { * Tests that drupal_get_filename() works when the file is not in database. */ public function testDrupalGetFilename() { - // Rebuild system.module.files state data. - // @todo Remove as part of https://www.drupal.org/node/2186491 - drupal_static_reset('system_rebuild_module_data'); - system_rebuild_module_data(); - // Retrieving the location of a module. $this->assertIdentical(drupal_get_filename('module', 'system'), 'core/modules/system/system.info.yml'); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php index a9cd9f1..30dd69f 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php @@ -217,10 +217,6 @@ public function testConfigEntityUninstall() { ] ); $entity2->save(); - // Perform a module rebuild so we can know where the node module is located - // and uninstall it. - // @todo Remove as part of https://www.drupal.org/node/2186491 - system_rebuild_module_data(); // Test that doing a config uninstall of the node module deletes entity2 // since it is dependent on entity1 which is dependent on the node module. $config_manager->uninstall('module', 'node'); @@ -359,10 +355,6 @@ public function testConfigEntityUninstallComplex(array $entity_id_suffixes) { $this->assertEqual($entity_4->uuid(), $config_entities['delete'][0]->uuid(), 'Entity 4 will be deleted.'); $this->assertEqual($entity_5->uuid(), $config_entities['update'][1]->uuid(), 'Entity 5 is updated.'); - // Perform a module rebuild so we can know where the node module is located - // and uninstall it. - // @todo Remove as part of https://www.drupal.org/node/2186491 - system_rebuild_module_data(); // Perform the uninstall. $config_manager->uninstall('module', 'node'); @@ -476,10 +468,6 @@ public function testConfigEntityUninstallThirdParty() { $this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_2->id()]); $this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_4->id()]); - // Perform a module rebuild so we can know where the node module is located - // and uninstall it. - // @todo Remove as part of https://www.drupal.org/node/2186491 - system_rebuild_module_data(); // Perform the uninstall. $config_manager->uninstall('module', 'node'); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRecreateTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRecreateTest.php index c69f9fe..218acfa 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRecreateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRecreateTest.php @@ -52,7 +52,8 @@ protected function setUp() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); } diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php index 9c1875c..6de26dd 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php @@ -57,7 +57,8 @@ protected function setUp() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); } diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php index 59f9cb2..237697a 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php @@ -56,7 +56,8 @@ protected function setUp() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); } diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php index 4024b7f..327a08c 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php @@ -56,7 +56,8 @@ protected function setUp() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNullStorageTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNullStorageTest.php index 6da9bb3..6e14593 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNullStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNullStorageTest.php @@ -63,7 +63,8 @@ public function testDeleteThroughImport() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); // Delete the contact message in sync. diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php index 96e469a..70a6517 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php @@ -37,7 +37,7 @@ class ModuleConfigureRouteTest extends KernelTestBase { protected function setUp() { parent::setUp(); $this->routeProvider = \Drupal::service('router.route_provider'); - $this->moduleInfo = system_rebuild_module_data(); + $this->moduleInfo = $this->container->get('extension.list.module')->getList(); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php index ff183c6..bc2a764 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php @@ -16,15 +16,6 @@ class ModuleInstallerTest extends KernelTestBase { /** - * Modules to install. - * - * The System module is required because system_rebuild_module_data() is used. - * - * @var array - */ - public static $modules = ['system']; - - /** * Tests that routes are rebuilt during install and uninstall of modules. * * @covers ::install diff --git a/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTest.php b/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTest.php index a71c3fe..300c022 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTest.php @@ -60,7 +60,7 @@ protected function setUp() { $this->container->get('theme_installer')->install(['stable']); // Enable all core modules. - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList(); $all_modules = array_filter($all_modules, function ($module) { // Filter contrib, hidden, experimental, already enabled modules, and // modules in the Testing package. diff --git a/core/tests/Drupal/KernelTests/Core/Theme/StableTemplateOverrideTest.php b/core/tests/Drupal/KernelTests/Core/Theme/StableTemplateOverrideTest.php index 40d31e6..2425287 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/StableTemplateOverrideTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/StableTemplateOverrideTest.php @@ -57,11 +57,8 @@ protected function setUp() { * Installs all core modules. */ protected function installAllModules() { - // Needed for system_rebuild_module_data(). - include_once $this->root . '/core/modules/system/system.module'; - // Enable all core modules. - $all_modules = system_rebuild_module_data(); + $all_modules = $this->container->get('extension.list.module')->getList(); $all_modules = array_filter($all_modules, function ($module) { // Filter contrib, hidden, experimental, already enabled modules, and // modules in the Testing package. diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php index 61f6475..ad4aa21 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php @@ -314,9 +314,7 @@ public function testThemeInfoAlter() { $themes = $this->themeHandler()->listInfo(); $this->assertFalse(isset($themes[$name]->info['regions']['test_region'])); - // Rebuild module data so we know where module_test is located. - // @todo Remove as part of https://www.drupal.org/node/2186491 - system_rebuild_module_data(); + // Install module_test. $this->moduleInstaller()->install(['module_test'], FALSE); $this->assertTrue($this->moduleHandler()->moduleExists('module_test')); diff --git a/core/tests/Drupal/Tests/ConfigTestTrait.php b/core/tests/Drupal/Tests/ConfigTestTrait.php index 330ff47..689d2b0 100644 --- a/core/tests/Drupal/Tests/ConfigTestTrait.php +++ b/core/tests/Drupal/Tests/ConfigTestTrait.php @@ -34,7 +34,8 @@ protected function configImporter() { $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), - $this->container->get('string_translation') + $this->container->get('string_translation'), + $this->container->get('extension.list.module') ); } // Always recalculate the changelist when called.