Commit 23fad5b6 authored by alexpott's avatar alexpott

Issue #2926068 by almaudoh, andypost, voleger, claudiu.cristea, Oleksiy,...

Issue #2926068 by almaudoh, andypost, voleger, claudiu.cristea, Oleksiy, YurkinPark, yo30, alexpott, dawehner, Berdir: Deprecate system_rebuild_module_data() and remove usages in core
parent d1ffb5bd
......@@ -536,7 +536,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
......@@ -1265,7 +1265,7 @@ services:
class: Drupal\Core\EventSubscriber\ConfigImportSubscriber
tags:
- { name: event_subscriber }
arguments: ['@theme_handler']
arguments: ['@theme_handler', '@extension.list.module']
config_snapshot_subscriber:
class: Drupal\Core\EventSubscriber\ConfigSnapshotSubscriber
tags:
......
......@@ -1133,7 +1133,7 @@ function drupal_flush_all_caches() {
\Drupal::service('twig')->invalidate();
// 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();
......
......@@ -1578,7 +1578,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
......@@ -2350,7 +2350,8 @@ function install_config_import_batch() {
\Drupal::service('module_handler'),
\Drupal::service('module_installer'),
\Drupal::service('theme_handler'),
\Drupal::service('string_translation')
\Drupal::service('string_translation'),
\Drupal::service('extension.list.module')
);
try {
......@@ -2421,7 +2422,8 @@ function install_config_revert_install_changes() {
\Drupal::service('module_handler'),
\Drupal::service('module_installer'),
\Drupal::service('theme_handler'),
\Drupal::service('string_translation')
\Drupal::service('string_translation'),
\Drupal::service('extension.list.module')
);
try {
$config_importer->import();
......
......@@ -48,7 +48,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])) {
......
......@@ -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;
......@@ -158,6 +159,13 @@ class ConfigImporter {
*/
protected $moduleInstaller;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* Constructs a configuration import object.
*
......@@ -180,8 +188,18 @@ 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
* The module extension list. This is left optional for BC reasons, but the
* optional usage is deprecated and will become required in Drupal 9.0.0.
*
* @todo Remove null default value https://www.drupal.org/node/2947083
*/
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.8.0 and will no longer be supported in Drupal 9.0.0. The extension list parameter is now required in the ConfigImporter constructor. See https://www.drupal.org/node/2943918', E_USER_DEPRECATED);
$extension_list_module = \Drupal::service('extension.list.module');
}
$this->moduleExtensionList = $extension_list_module;
$this->storageComparer = $storage_comparer;
$this->eventDispatcher = $event_dispatcher;
$this->configManager = $config_manager;
......@@ -369,7 +387,7 @@ protected function createExtensionChangelist() {
}
// Get a list of modules with dependency weights as values.
$module_data = system_rebuild_module_data();
$module_data = $this->moduleExtensionList->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) {
......
......@@ -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.
......@@ -40,9 +41,12 @@ class ConfigImportSubscriber extends ConfigImportValidateEventSubscriberBase {
*
* @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(ThemeHandlerInterface $theme_handler) {
public function __construct(ThemeHandlerInterface $theme_handler, ModuleExtensionList $extension_list_module) {
$this->themeHandler = $theme_handler;
$this->moduleExtensionList = $extension_list_module;
}
/**
......@@ -108,7 +112,7 @@ protected function validateModules(ConfigImporter $config_importer) {
}
// 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]));
......@@ -214,7 +218,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
......@@ -310,18 +314,6 @@ protected function getThemeData() {
return $this->themeData;
}
/**
* 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.
*
......
......@@ -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.
......@@ -335,7 +337,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.
......
......@@ -12,14 +12,24 @@ 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.
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
* The module extension list.
*/
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 +51,13 @@ 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 : [];
if ($this->moduleExtensionList->exists($module)) {
return $this->moduleExtensionList->get($module)->info;
}
return [];
}
}
......@@ -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()]);
......
......@@ -13,6 +13,7 @@
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
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 ConfigSingleImportForm extends ConfirmFormBase {
*/
protected $themeHandler;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* The module installer.
*
......@@ -148,8 +156,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(EntityTypeManagerInterface $entity_type_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(EntityTypeManagerInterface $entity_type_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->entityTypeManager = $entity_type_manager;
$this->configStorage = $config_storage;
$this->renderer = $renderer;
......@@ -162,6 +172,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Sto
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->themeHandler = $theme_handler;
$this->moduleExtensionList = $extension_list_module;
}
/**
......@@ -178,7 +189,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')
);
}
......@@ -364,7 +376,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
$this->moduleHandler,
$this->moduleInstaller,
$this->themeHandler,
$this->getStringTranslation()
$this->getStringTranslation(),
$this->moduleExtensionList
);
try {
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\Importer\ConfigImporterBatch;
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.
*
......@@ -129,8 +137,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;
......@@ -142,6 +152,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;
}
/**
......@@ -159,7 +170,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')
);
}
......@@ -328,7 +340,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()) {
$this->messenger()->addStatus($this->t('Another request may be synchronizing configuration already.'));
......
......@@ -45,7 +45,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.
......@@ -86,7 +86,7 @@ public function testInstallUninstall() {
// Purge the field data.
field_purge_batch(1000);
$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));
......
......@@ -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']);
......
......@@ -49,7 +49,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')
);
}
......
......@@ -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')
);
}
......
......@@ -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 = \Drupal::service('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.
......
......@@ -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();
}
/**
......
......@@ -488,7 +488,7 @@ public function testDependencyRemoval() {
drupal_static_reset('filter_formats');
\Drupal::entityTypeManager()->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
......
......@@ -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'];
}
......
......@@ -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 = \Drupal::service('extension.list.module')->getList();
$all_modules = array_filter($all_modules, function ($module) {
// Filter contrib, hidden, already enabled modules and modules in the
// Testing package.
......
......@@ -25,7 +25,7 @@ class TestCoverageTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$all_modules = system_rebuild_module_data();
$all_modules = \Drupal::service('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.
......
......@@ -48,7 +48,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')
);
}
......
......@@ -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);
......
......@@ -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.
......
......@@ -8,6 +8,7 @@
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\InfoParserException;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Form\FormBase;
......@@ -66,6 +67,13 @@ class ModulesListForm extends FormBase {
*/
protected $permissionHandler;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* {@inheritdoc}
*/
......@@ -76,7 +84,8 @@ public static function create(ContainerInterface $container) {
$container->get('keyvalue.expirable')->get('module_list'),
$container->get('access_manager'),
$container->get('current_user'),
$container->get('user.permissions')
$container->get('user.permissions'),
$container->get('extension.list.module')
);
}
......@@ -95,8 +104,11 @@ public static function create(ContainerInterface $container) {
* The current user.
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
* The permission handler.
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
* The module extension list.
*/
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, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, AccountInterface $current_user, PermissionHandlerInterface $permission_handler, ModuleExtensionList $extension_list_module) {
$this->moduleExtensionList = $extension_list_module;
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->keyValueExpirable = $key_value_expirable;
......@@ -145,7 +157,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Sort all modules by their names.
try {
$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');
}
catch (InfoParserException $e) {
......@@ -377,7 +391,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)) {
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -64,6 +65,13 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
*/
protected $modules = [];
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* Constructs a ModulesUninstallConfirmForm object.
*
......@@ -75,12 +83,15 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
* The configuration manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type 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, EntityTypeManagerInterface $entity_type_manager) {
public function __construct(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager, ModuleExtensionList $extension_list_module) {
$this->moduleInstaller = $module_installer;
$this->keyValueExpirable = $key_value_expirable;
$this->configManager = $config_manager;
$this->entityTypeManager = $entity_type_manager;
$this->moduleExtensionList = $extension_list_module;
}
/**
......@@ -91,7 +102,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_type.manager')
$container->get('entity_type.manager'),
$container->get('extension.list.module')
);
}
......@@ -144,7 +156,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'] = '<p>' . $this->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>';
$form['modules'] = [
'#theme' => 'item_list',
......
......@@ -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;
......@@ -37,6 +38,13 @@ class ModulesUninstallForm extends FormBase {
*/
protected $keyValueExpirable;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* {@inheritdoc}
*/
......@@ -44,7 +52,8 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('module_handler'),
$container->get('module_installer'),
$container->get('keyvalue.expirable')->get('modules_uninstall')
$container->get('keyvalue.expirable')->get('modules_uninstall'),
$container->get('extension.list.module')
);
}
......@@ -57,8 +66,11 @@ public static function create(ContainerInterface $container) {
* The module installer.
* @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable
* The key value expirable factory.
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
* The module extension list.
*/
public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable) {
public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ModuleExtensionList $extension_list_module) {
$this->moduleExtensionList = $extension_list_module;
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->keyValueExpirable = $key_value_expirable;
......@@ -78,10 +90,9 @@ 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.