Commit 5109a932 authored by catch's avatar catch
Browse files

Issue #697946 by voleger, pguillard, pillarsdotnet, andypost, alansaviolobo,...

Issue #697946 by voleger, pguillard, pillarsdotnet, andypost, alansaviolobo, alexpott, vaibhavjain, MerryHamster, sja112, kim.pepper, shaktik, ravi.shankar, Pooja Ganjage, daffie, Mile23, legolasbo, joelpittet, almaudoh, xjm, Berdir, scor: Properly deprecate module_load_include() and move it into \Drupal::moduleHandler() service

(cherry picked from commit a9f20f76)
parent e1b059c3
......@@ -1723,7 +1723,8 @@ function install_download_additional_translations_operations(&$install_state) {
* The batch definition, if there are language files to import.
*/
function install_import_translations(&$install_state) {
\Drupal::moduleHandler()->loadInclude('locale', 'translation.inc');
$module_handler = \Drupal::moduleHandler();
$module_handler->loadInclude('locale', 'inc', 'locale.translation');
// If there is more than one language or the single one is not English, we
// should import translations.
......@@ -1741,7 +1742,7 @@ function install_import_translations(&$install_state) {
$operations[] = ['locale_translation_batch_fetch_import', ['drupal', $language->getId(), []]];
}
module_load_include('fetch.inc', 'locale');
$module_handler->loadInclude('locale', 'inc', 'locale.fetch');
$batch = [
'operations' => $operations,
'title' => t('Updating translations.'),
......@@ -1763,7 +1764,8 @@ function install_import_translations(&$install_state) {
* Server access pattern (to replace language code, version number, etc. in).
*/
function _install_prepare_import($langcodes, $server_pattern) {
\Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
$module_handler = \Drupal::moduleHandler();
$module_handler->loadInclude('locale', 'inc', 'locale.bulk');
$matches = [];
foreach ($langcodes as $langcode) {
......@@ -1790,7 +1792,7 @@ function _install_prepare_import($langcodes, $server_pattern) {
'status' => 1,
];
\Drupal::service('locale.project')->set($data['name'], $data);
module_load_include('compare.inc', 'locale');
$module_handler->loadInclude('locale', 'inc', 'locale.compare');
// Reset project information static cache so that it uses the data
// set above.
locale_translation_clear_cache_projects();
......
......@@ -20,7 +20,16 @@ function module_load_install($module) {
// Make sure the installation API is available
include_once __DIR__ . '/install.inc';
return module_load_include('install', $module);
if (\Drupal::hasService('extension.list.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;
return $file;
}
}
return FALSE;
}
/**
......@@ -47,15 +56,18 @@ function module_load_install($module) {
* (optional) The base file name (without the $type extension). If omitted,
* $module is used; i.e., resulting in "$module.$type" by default.
*
* @return
* @return string|false
* The name of the included file, if successful; FALSE otherwise.
*
* @todo The module_handler service has a loadInclude() method which performs
* this same task but only for enabled modules. Figure out a way to move this
* functionality entirely into the module_handler while keeping the ability to
* load the files of disabled modules.
* @deprecated in drupal:9.4.0 and is removed from drupal:11.0.0.
* Use \Drupal::moduleHandler()->loadInclude($module, $type, $name = NULL).
* Note that including code from uninstalled extensions is no longer
* supported.
*
* @see https://www.drupal.org/node/2948698
*/
function module_load_include($type, $module, $name = NULL) {
@trigger_error("module_load_include() is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude(). Note that including code from uninstalled extensions is no longer supported. See https://www.drupal.org/project/drupal/issues/697946", E_USER_DEPRECATED);
if (!isset($name)) {
$name = $module;
}
......
......@@ -287,7 +287,7 @@ function update_invoke_post_update($function, &$context) {
}
[$module, $name] = explode('_post_update_', $function, 2);
module_load_include('php', $module, $module . '.post_update');
\Drupal::moduleHandler()->loadInclude($module, 'php', $module . '.post_update');
if (function_exists($function)) {
try {
$ret['results']['query'] = $function($context['sandbox']);
......
......@@ -46,10 +46,11 @@ class FormState implements FormStateInterface {
* - files: An optional array defining include files that need to be loaded
* for building the form. Each array entry may be the path to a file or
* another array containing values for the parameters 'type', 'module' and
* 'name' as needed by module_load_include(). The files listed here are
* automatically loaded by \Drupal::formBuilder()->getCache(). By default
* the current menu router item's 'file' definition is added, if any. Use
* self::loadInclude() to add include files from a form constructor.
* 'name' as needed by \Drupal::moduleHandler()->loadInclude(). The files
* listed here are automatically loaded by
* \Drupal::formBuilder()->getCache(). By default the current menu router
* item's 'file' definition is added, if any. Use self::loadInclude() to
* add include files from a form constructor.
* - form_id: Identification of the primary form being constructed and
* processed.
* - base_form_id: Identification for a base form, as declared in the form
......
......@@ -49,11 +49,11 @@ public function setCompleteForm(array &$complete_form);
* $form_state->loadInclude('node', 'inc', 'node.admin');
* @endcode
*
* Use this function instead of module_load_include() from inside a form
* constructor or any form processing logic as it ensures that the include file
* is loaded whenever the form is processed. In contrast to using
* module_load_include() directly, this method makes sure the include file is
* correctly loaded also if the form is cached.
* Use this function instead of \Drupal::moduleHandler()->loadInclude()
* from inside a form constructor or any form processing logic as it ensures
* that the include file is loaded whenever the form is processed. In contrast
* to using \Drupal::moduleHandler()->loadInclude() directly, this method
* makes sure the include file is correctly loaded also if the form is cached.
*
* @param string $module
* The module to which the include file belongs.
......@@ -67,7 +67,7 @@ public function setCompleteForm(array &$complete_form);
* The filepath of the loaded include file, or FALSE if the include file was
* not found or has been loaded already.
*
* @see module_load_include()
* @see \Drupal\Core\Extension\ModuleHandlerInterface::loadInclude()
*/
public function loadInclude($module, $type, $name = NULL);
......
......@@ -87,7 +87,7 @@ public function getSchemaUpdates() {
if (!self::canUpdate($this->name)) {
return [];
}
module_load_include('install', $this->name);
\Drupal::moduleHandler()->loadInclude($this->name, 'install');
if (!\Drupal::service('update.update_hook_registry')->getAvailableUpdates($this->name)) {
return [];
......
......@@ -507,7 +507,7 @@ function content_translation_form_field_config_edit_form_alter(array &$form, For
}
if ($field->isTranslatable()) {
module_load_include('inc', 'content_translation', 'content_translation.admin');
\Drupal::moduleHandler()->loadInclude('content_translation', 'inc', 'content_translation.admin');
$element = content_translation_field_sync_widget($field);
if ($element) {
$form['third_party_settings']['content_translation']['translation_sync'] = $element;
......@@ -651,7 +651,7 @@ function content_translation_language_configuration_element_submit(array $form,
* Implements hook_form_FORM_ID_alter() for language_content_settings_form().
*/
function content_translation_form_language_content_settings_form_alter(array &$form, FormStateInterface $form_state) {
module_load_include('inc', 'content_translation', 'content_translation.admin');
\Drupal::moduleHandler()->loadInclude('content_translation', 'inc', 'content_translation.admin');
_content_translation_form_language_content_settings_form_alter($form, $form_state);
}
......@@ -659,7 +659,7 @@ function content_translation_form_language_content_settings_form_alter(array &$f
* Implements hook_preprocess_HOOK() for language-content-settings-table.html.twig.
*/
function content_translation_preprocess_language_content_settings_table(&$variables) {
module_load_include('inc', 'content_translation', 'content_translation.admin');
\Drupal::moduleHandler()->loadInclude('content_translation', 'inc', 'content_translation.admin');
_content_translation_preprocess_language_content_settings_table($variables);
}
......
......@@ -182,7 +182,7 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$
if (isset($source->type)) {
if ($source->type == LOCALE_TRANSLATION_REMOTE || $source->type == LOCALE_TRANSLATION_LOCAL) {
$file = $source->files[LOCALE_TRANSLATION_LOCAL];
module_load_include('bulk.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.bulk');
$options += [
'message' => t('Importing %langcode translation for %project.', ['%langcode' => $langcode, '%project' => $source->project]),
];
......@@ -217,7 +217,7 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$
* Batch results.
*/
function locale_translation_batch_fetch_finished($success, $results) {
module_load_include('bulk.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.bulk');
if ($success) {
\Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME);
}
......
......@@ -88,7 +88,7 @@ function locale_translate_batch_import_files(array $options, $force = FALSE) {
* An array of interface translation files keyed by their URI.
*/
function locale_translate_get_interface_translation_files(array $projects = [], array $langcodes = []) {
module_load_include('compare.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
$files = [];
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
......
......@@ -29,7 +29,7 @@
* Batch definition array.
*/
function locale_translation_batch_update_build($projects = [], $langcodes = [], $options = []) {
module_load_include('compare.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
$status_options = $options;
......
......@@ -231,7 +231,7 @@ function locale_configurable_language_delete(ConfigurableLanguageInterface $lang
\Drupal::service('locale.storage')->deleteTranslations(['language' => $language->id()]);
// Remove interface translation files.
module_load_include('inc', 'locale', 'locale.bulk');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.bulk');
locale_translate_delete_translation_files([], [$language->id()]);
// Remove translated configuration objects.
......@@ -359,7 +359,7 @@ function locale_cron() {
// and a translatable language was set.
// Update tasks are added to the queue here but processed by Drupal's cron.
if (\Drupal::config('locale.settings')->get('translation.update_interval_days') && locale_translatable_language_list()) {
module_load_include('translation.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.translation');
locale_cron_fill_queue();
}
}
......@@ -410,15 +410,16 @@ function locale_system_update(array $components) {
// because it would break out of the installer flow. We have
// built-in support for translation imports in the installer.
if (!InstallerKernel::installationAttempted() && locale_translatable_language_list()) {
$module_handler = \Drupal::moduleHandler();
if (\Drupal::config('locale.settings')->get('translation.import_enabled')) {
module_load_include('compare.inc', 'locale');
$module_handler->loadInclude('locale', 'inc', 'locale.compare');
// Update the list of translatable projects and start the import batch.
// Only when new projects are added the update batch will be triggered.
// Not each enabled module will introduce a new project. E.g. sub modules.
$projects = array_keys(locale_translation_build_projects());
if ($list = array_intersect($list, $projects)) {
module_load_include('fetch.inc', 'locale');
$module_handler->loadInclude('locale', 'inc', 'locale.fetch');
// Get translation status of the projects, download and update
// translations.
$options = _locale_translation_default_update_options();
......@@ -431,7 +432,7 @@ function locale_system_update(array $components) {
// this component may have installed configuration from any number of other
// components. Do this even if import is not enabled because parsing new
// configuration may expose new source strings.
\Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
$module_handler->loadInclude('locale', 'inc', 'locale.bulk');
if ($batch = locale_config_batch_update_components([])) {
batch_set($batch);
}
......@@ -453,8 +454,9 @@ function locale_system_remove($components) {
$components += ['module' => [], 'theme' => []];
$list = array_merge($components['module'], $components['theme']);
if (locale_translatable_language_list()) {
module_load_include('compare.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
$module_handler = \Drupal::moduleHandler();
$module_handler->loadInclude('locale', 'inc', 'locale.compare');
$module_handler->loadInclude('locale', 'inc', 'locale.bulk');
// Only when projects are removed, the translation files and records will be
// deleted. Not each disabled module will remove a project, e.g., sub
......@@ -863,7 +865,7 @@ function locale_translation_file_history_delete($projects = [], $langcodes = [])
function locale_translation_get_status($projects = NULL, $langcodes = NULL) {
$result = [];
$status = \Drupal::keyValue('locale.translation_status')->getAll();
module_load_include('translation.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.translation');
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
......@@ -899,7 +901,7 @@ function locale_translation_get_status($projects = NULL, $langcodes = NULL) {
*/
function locale_translation_status_save($project, $langcode, $type, $data) {
// Load the translation status or build it if not already available.
module_load_include('translation.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.translation');
$status = locale_translation_get_status();
if (empty($status)) {
$projects = locale_translation_get_projects([$project]);
......
......@@ -63,7 +63,7 @@ function locale_translation_get_projects(array $project_names = []) {
// https://www.drupal.org/node/1777106 is a follow-up issue to make the
// check for possible out-of-date project information more robust.
if ($row_count == 0) {
module_load_include('compare.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
// At least the core project should be in the database, so we build the
// data if none are found.
locale_translation_build_projects();
......@@ -357,7 +357,7 @@ function locale_cron_fill_queue() {
// For each project+language combination a number of tasks are added to
// the queue.
if ($updates) {
module_load_include('fetch.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.fetch');
$options = _locale_translation_default_update_options();
$queue = \Drupal::queue('locale_translation', TRUE);
......
......@@ -20,7 +20,7 @@ class LocaleUpdateDevelopmentReleaseTest extends BrowserTestBase {
protected function setUp(): void {
parent::setUp();
module_load_include('compare.inc', 'locale');
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
$admin_user = $this->drupalCreateUser([
'administer modules',
'administer languages',
......
......@@ -22,8 +22,9 @@ class LocaleUpdateTest extends LocaleUpdateBase {
*/
protected function setUp(): void {
parent::setUp();
module_load_include('compare.inc', 'locale');
module_load_include('fetch.inc', 'locale');
$module_handler = \Drupal::moduleHandler();
$module_handler->loadInclude('locale', 'inc', 'locale.compare');
$module_handler->loadInclude('locale', 'inc', 'locale.fetch');
$admin_user = $this->drupalCreateUser([
'administer modules',
'administer site configuration',
......
......@@ -640,13 +640,13 @@ function node_user_cancel($edit, UserInterface $account, $method) {
->accessCheck(FALSE)
->condition('uid', $account->id())
->execute();
module_load_include('inc', 'node', 'node.admin');
\Drupal::moduleHandler()->loadInclude('node', 'inc', 'node.admin');
node_mass_update($nids, ['status' => 0], NULL, TRUE);
break;
case 'user_cancel_reassign':
// Anonymize all of the nodes for this old account.
module_load_include('inc', 'node', 'node.admin');
\Drupal::moduleHandler()->loadInclude('node', 'inc', 'node.admin');
$vids = \Drupal::entityTypeManager()->getStorage('node')->userRevisionIds($account);
node_mass_update($vids, [
'uid' => 0,
......
......@@ -54,7 +54,8 @@ function entity_test_schema() {
return $schema;
}
$module_handler = \Drupal::moduleHandler();
$index = \Drupal::state()->get('entity_test.db_updates.entity_definition_updates');
module_load_include('inc', 'entity_test', 'update/entity_definition_updates_' . $index);
$module_handler->loadInclude('entity_test', 'inc', 'update/entity_definition_updates_' . $index);
$index = \Drupal::state()->get('entity_test.db_updates.status_report');
module_load_include('inc', 'entity_test', 'update/status_report_' . $index);
$module_handler->loadInclude('entity_test', 'inc', 'update/status_report_' . $index);
......@@ -418,7 +418,7 @@ public function testUpdateShowDisabledThemes() {
* Tests updates with a hidden base theme.
*/
public function testUpdateHiddenBaseTheme() {
module_load_include('compare.inc', 'update');
\Drupal::moduleHandler()->loadInclude('update', 'inc', 'update.compare');
// Install the subtheme.
\Drupal::service('theme_installer')->install(['update_test_subtheme']);
......
......@@ -36,7 +36,7 @@ function update_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
if ($available = update_get_available(FALSE)) {
module_load_include('inc', 'update', 'update.compare');
\Drupal::moduleHandler()->loadInclude('update', 'inc', 'update.compare');
$data = update_calculate_project_data($available);
// First, populate the requirements for core:
$requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
......
......@@ -193,7 +193,7 @@ function update_cron() {
if ((REQUEST_TIME - $last_email_notice) > $interval) {
// If configured time between notifications elapsed, send email about
// updates possibly available.
module_load_include('inc', 'update', 'update.fetch');
\Drupal::moduleHandler()->loadInclude('update', 'inc', 'update.fetch');
_update_cron_notify();
}
......@@ -276,7 +276,7 @@ function _update_no_data() {
* @see \Drupal\update\UpdateManager::getProjects()
*/
function update_get_available($refresh = FALSE) {
module_load_include('inc', 'update', 'update.compare');
\Drupal::moduleHandler()->loadInclude('update', 'inc', 'update.compare');
$needs_refresh = FALSE;
// Grab whatever data we currently have.
......
......@@ -43,7 +43,7 @@ function hook_user_cancel($edit, UserInterface $account, $method) {
switch ($method) {
case 'user_cancel_block_unpublish':
// Unpublish nodes (current revisions).
module_load_include('inc', 'node', 'node.admin');
\Drupal::moduleHandler()->loadInclude('node', 'inc', 'node.admin');
$nodes = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('uid', $account->id())
......@@ -53,7 +53,7 @@ function hook_user_cancel($edit, UserInterface $account, $method) {
case 'user_cancel_reassign':
// Anonymize nodes (current revisions).
module_load_include('inc', 'node', 'node.admin');
\Drupal::moduleHandler()->loadInclude('node', 'inc', 'node.admin');
$nodes = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('uid', $account->id())
......
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