Issue #2010380 by alexpott, TR, tstoeckler, MerryHamster, sanjayk, andypost, chx, Pancho, daffie: Deprecate module_load_install() and replace it with ModuleHandler::loadInstall

merge-requests/1634/merge
catch 2022-01-12 13:33:05 +00:00
parent c5bd67a8d1
commit 9defd332d4
14 changed files with 42 additions and 15 deletions

View File

@ -84,7 +84,7 @@ function drupal_load_updates() {
foreach (\Drupal::service('update.update_hook_registry')->getAllInstalledVersions() as $module => $schema_version) { foreach (\Drupal::service('update.update_hook_registry')->getAllInstalledVersions() as $module => $schema_version) {
if ($extension_list_module->exists($module) && !$extension_list_module->checkIncompatibility($module)) { if ($extension_list_module->exists($module) && !$extension_list_module->checkIncompatibility($module)) {
if ($schema_version > -1) { if ($schema_version > -1) {
module_load_install($module); \Drupal::moduleHandler()->loadInclude($module, 'install');
} }
} }
} }
@ -1033,7 +1033,12 @@ function drupal_requirements_severity(&$requirements) {
* TRUE or FALSE, depending on whether the requirements are met. * TRUE or FALSE, depending on whether the requirements are met.
*/ */
function drupal_check_module($module) { function drupal_check_module($module) {
module_load_install($module); /** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */
$module_list = \Drupal::service('extension.list.module');
$file = DRUPAL_ROOT . '/' . $module_list->getPath($module) . "/$module.install";
if (is_file($file)) {
require_once $file;
}
// Check requirements // Check requirements
$requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', ['install']); $requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', ['install']);
if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) { if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {

View File

@ -15,8 +15,15 @@ use Drupal\Core\Extension\ExtensionDiscovery;
* *
* @return * @return
* The name of the module's install file, if successful; FALSE otherwise. * The name of the module's install file, if successful; FALSE otherwise.
*
* @deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use
* \Drupal::moduleHandler()->loadInclude($module, 'install') instead. Note,
* the replacement no longer allows including code from uninstalled modules.
*
* @see https://www.drupal.org/node/3220952
*/ */
function module_load_install($module) { function module_load_install($module) {
@trigger_error('module_load_install() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude($module, \'install\'). Note, the replacement no longer allows including code from uninstalled modules. See https://www.drupal.org/project/drupal/issues/2010380', E_USER_DEPRECATED);
// Make sure the installation API is available // Make sure the installation API is available
include_once __DIR__ . '/install.inc'; include_once __DIR__ . '/install.inc';

View File

@ -115,7 +115,7 @@ function _update_fix_missing_schema() {
// don't, detect and fix the problem. // don't, detect and fix the problem.
if (!isset($versions[$module])) { if (!isset($versions[$module])) {
// Ensure the .install file is loaded. // Ensure the .install file is loaded.
module_load_install($module); $module_handler->loadInclude($module, 'install');
$all_updates = $update_registry->getAvailableUpdates($module); $all_updates = $update_registry->getAvailableUpdates($module);
// If the schema version of a module hasn't been recorded, we cannot // If the schema version of a module hasn't been recorded, we cannot
// know the actual schema version a module is at, because // know the actual schema version a module is at, because
@ -704,7 +704,7 @@ function update_retrieve_dependencies() {
} }
$function = $module . '_update_dependencies'; $function = $module . '_update_dependencies';
// Ensure install file is loaded. // Ensure install file is loaded.
module_load_install($module); \Drupal::moduleHandler()->loadInclude($module, 'install');
if (function_exists($function)) { if (function_exists($function)) {
$updated_dependencies = $function(); $updated_dependencies = $function();
// Each implementation of hook_update_dependencies() returns a // Each implementation of hook_update_dependencies() returns a

View File

@ -242,7 +242,7 @@ class ModuleInstaller implements ModuleInstallerInterface {
// Load the module's .module and .install files. // Load the module's .module and .install files.
$this->moduleHandler->load($module); $this->moduleHandler->load($module);
module_load_install($module); $this->moduleHandler->loadInclude($module, 'install');
if (!InstallerKernel::installationAttempted()) { if (!InstallerKernel::installationAttempted()) {
// Replace the route provider service with a version that will rebuild // Replace the route provider service with a version that will rebuild
@ -468,7 +468,7 @@ class ModuleInstaller implements ModuleInstallerInterface {
$this->moduleHandler->invokeAll('module_preuninstall', [$module]); $this->moduleHandler->invokeAll('module_preuninstall', [$module]);
// Uninstall the module. // Uninstall the module.
module_load_install($module); $this->moduleHandler->loadInclude($module, 'install');
$this->moduleHandler->invoke($module, 'uninstall', [$sync_status]); $this->moduleHandler->invoke($module, 'uninstall', [$sync_status]);
// Remove all configuration belonging to the module. // Remove all configuration belonging to the module.

View File

@ -93,7 +93,12 @@ class SelectProfileForm extends FormBase {
// profile's which implement hook_INSTALL() are not supported. // profile's which implement hook_INSTALL() are not supported.
// @todo https://www.drupal.org/project/drupal/issues/2982052 Remove // @todo https://www.drupal.org/project/drupal/issues/2982052 Remove
// this restriction. // this restriction.
module_load_install($extensions['profile']); $root = \Drupal::root();
include_once $root . '/core/includes/install.inc';
$file = $root . '/' . $install_state['profiles'][$extensions['profile']]->getPath() . "/{$extensions['profile']}.install";
if (is_file($file)) {
require_once $file;
}
if (!function_exists($extensions['profile'] . '_install')) { if (!function_exists($extensions['profile'] . '_install')) {
$form['profile']['#options'][static::CONFIG_INSTALL_PROFILE_KEY] = $this->t('Use existing configuration'); $form['profile']['#options'][static::CONFIG_INSTALL_PROFILE_KEY] = $this->t('Use existing configuration');
$form['profile'][static::CONFIG_INSTALL_PROFILE_KEY]['#description'] = [ $form['profile'][static::CONFIG_INSTALL_PROFILE_KEY]['#description'] = [

View File

@ -92,7 +92,7 @@ class SitesDirectoryHardeningTest extends BrowserTestBase {
* An array of system requirements. * An array of system requirements.
*/ */
protected function checkSystemRequirements() { protected function checkSystemRequirements() {
module_load_install('system'); \Drupal::moduleHandler()->loadInclude('system', 'install');
return system_requirements('runtime'); return system_requirements('runtime');
} }

View File

@ -18,7 +18,7 @@ use Drupal\update\UpdateManagerInterface;
*/ */
function _update_cron_notify() { function _update_cron_notify() {
$update_config = \Drupal::config('update.settings'); $update_config = \Drupal::config('update.settings');
module_load_install('update'); \Drupal::moduleHandler()->loadInclude('update', 'install');
$status = update_requirements('runtime'); $status = update_requirements('runtime');
$params = []; $params = [];
$notify_all = ($update_config->get('notification.threshold') == 'all'); $notify_all = ($update_config->get('notification.threshold') == 'all');

View File

@ -92,7 +92,7 @@ function update_page_top() {
break; break;
} }
module_load_install('update'); \Drupal::moduleHandler()->loadInclude('update', 'install');
$status = update_requirements('runtime'); $status = update_requirements('runtime');
foreach (['core', 'contrib'] as $report_type) { foreach (['core', 'contrib'] as $report_type) {
$type = 'update_' . $report_type; $type = 'update_' . $report_type;

View File

@ -64,7 +64,7 @@ class EntityFieldTest extends EntityKernelTestBase {
} }
// Create the test field. // Create the test field.
module_load_install('entity_test'); $this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install(); entity_test_install();
// Install required default configuration for filter module. // Install required default configuration for filter module.

View File

@ -56,7 +56,7 @@ abstract class EntityLanguageTestBase extends EntityKernelTestBase {
$this->installConfig(['language']); $this->installConfig(['language']);
// Create the test field. // Create the test field.
module_load_install('entity_test'); $this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install(); entity_test_install();
// Enable translations for the test entity type. // Enable translations for the test entity type.

View File

@ -52,7 +52,7 @@ class EntityValidationTest extends EntityKernelTestBase {
$this->installEntitySchema('entity_test_mulrev_changed'); $this->installEntitySchema('entity_test_mulrev_changed');
// Create the test field. // Create the test field.
module_load_install('entity_test'); $this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install(); entity_test_install();
// Install required default configuration for filter module. // Install required default configuration for filter module.

View File

@ -22,4 +22,14 @@ class ModuleLegacyTest extends KernelTestBase {
} }
/**
* Test deprecation of module_load_install() function.
*/
public function testModuleLoadInstall() {
$this->assertFalse(\Drupal::moduleHandler()->moduleExists('node'), 'The Node module is not installed');
$this->expectDeprecation('module_load_install() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude($module, \'install\'). Note, the replacement no longer allows including code from uninstalled modules. See https://www.drupal.org/project/drupal/issues/2010380');
$filename = module_load_install('node');
$this->assertStringEndsWith("node.install", $filename);
}
} }

View File

@ -54,7 +54,7 @@ class FieldAccessTest extends KernelTestBase {
// The users table is needed for creating dummy user accounts. // The users table is needed for creating dummy user accounts.
$this->installEntitySchema('user'); $this->installEntitySchema('user');
// Register entity_test text field. // Register entity_test text field.
module_load_install('entity_test'); $this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install(); entity_test_install();
} }

View File

@ -45,7 +45,7 @@ class FileSystemRequirementsTest extends KernelTestBase {
* An array of system requirements. * An array of system requirements.
*/ */
protected function checkSystemRequirements() { protected function checkSystemRequirements() {
module_load_install('system'); $this->container->get('module_handler')->loadInclude('system', 'install');
return system_requirements('runtime'); return system_requirements('runtime');
} }