Commit 863214e9 authored by catch's avatar catch
Browse files

Issue #2010380 by alexpott, TR, tstoeckler, MerryHamster, sanjayk, andypost,...

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

(cherry picked from commit 9defd332)
parent 02a261ea
......@@ -84,7 +84,7 @@ function drupal_load_updates() {
foreach (\Drupal::service('update.update_hook_registry')->getAllInstalledVersions() as $module => $schema_version) {
if ($extension_list_module->exists($module) && !$extension_list_module->checkIncompatibility($module)) {
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.
*/
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
$requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', ['install']);
if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {
......
......@@ -15,8 +15,15 @@
*
* @return
* 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) {
@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
include_once __DIR__ . '/install.inc';
......
......@@ -115,7 +115,7 @@ function _update_fix_missing_schema() {
// don't, detect and fix the problem.
if (!isset($versions[$module])) {
// Ensure the .install file is loaded.
module_load_install($module);
$module_handler->loadInclude($module, 'install');
$all_updates = $update_registry->getAvailableUpdates($module);
// If the schema version of a module hasn't been recorded, we cannot
// know the actual schema version a module is at, because
......@@ -704,7 +704,7 @@ function update_retrieve_dependencies() {
}
$function = $module . '_update_dependencies';
// Ensure install file is loaded.
module_load_install($module);
\Drupal::moduleHandler()->loadInclude($module, 'install');
if (function_exists($function)) {
$updated_dependencies = $function();
// Each implementation of hook_update_dependencies() returns a
......
......@@ -242,7 +242,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// Load the module's .module and .install files.
$this->moduleHandler->load($module);
module_load_install($module);
$this->moduleHandler->loadInclude($module, 'install');
if (!InstallerKernel::installationAttempted()) {
// Replace the route provider service with a version that will rebuild
......@@ -468,7 +468,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
$this->moduleHandler->invokeAll('module_preuninstall', [$module]);
// Uninstall the module.
module_load_install($module);
$this->moduleHandler->loadInclude($module, 'install');
$this->moduleHandler->invoke($module, 'uninstall', [$sync_status]);
// Remove all configuration belonging to the module.
......
......@@ -93,7 +93,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $install_
// profile's which implement hook_INSTALL() are not supported.
// @todo https://www.drupal.org/project/drupal/issues/2982052 Remove
// 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')) {
$form['profile']['#options'][static::CONFIG_INSTALL_PROFILE_KEY] = $this->t('Use existing configuration');
$form['profile'][static::CONFIG_INSTALL_PROFILE_KEY]['#description'] = [
......
......@@ -92,7 +92,7 @@ public function testSitesDirectoryHardeningConfig() {
* An array of system requirements.
*/
protected function checkSystemRequirements() {
module_load_install('system');
\Drupal::moduleHandler()->loadInclude('system', 'install');
return system_requirements('runtime');
}
......
......@@ -18,7 +18,7 @@
*/
function _update_cron_notify() {
$update_config = \Drupal::config('update.settings');
module_load_install('update');
\Drupal::moduleHandler()->loadInclude('update', 'install');
$status = update_requirements('runtime');
$params = [];
$notify_all = ($update_config->get('notification.threshold') == 'all');
......
......@@ -92,7 +92,7 @@ function update_page_top() {
break;
}
module_load_install('update');
\Drupal::moduleHandler()->loadInclude('update', 'install');
$status = update_requirements('runtime');
foreach (['core', 'contrib'] as $report_type) {
$type = 'update_' . $report_type;
......
......@@ -64,7 +64,7 @@ protected function setUp(): void {
}
// Create the test field.
module_load_install('entity_test');
$this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install();
// Install required default configuration for filter module.
......
......@@ -56,7 +56,7 @@ protected function setUp() {
$this->installConfig(['language']);
// Create the test field.
module_load_install('entity_test');
$this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install();
// Enable translations for the test entity type.
......
......@@ -52,7 +52,7 @@ protected function setUp(): void {
$this->installEntitySchema('entity_test_mulrev_changed');
// Create the test field.
module_load_install('entity_test');
$this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install();
// Install required default configuration for filter module.
......
......@@ -22,4 +22,14 @@ public function testModuleLoadInclude() {
}
/**
* 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);
}
}
......@@ -54,7 +54,7 @@ protected function setUp(): void {
// The users table is needed for creating dummy user accounts.
$this->installEntitySchema('user');
// Register entity_test text field.
module_load_install('entity_test');
$this->container->get('module_handler')->loadInclude('entity_test', 'install');
entity_test_install();
}
......
......@@ -45,7 +45,7 @@ public function testSettingsExist() {
* An array of system requirements.
*/
protected function checkSystemRequirements() {
module_load_install('system');
$this->container->get('module_handler')->loadInclude('system', 'install');
return system_requirements('runtime');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment