Commit a9f20f76 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
parent 837b829a
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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();
+18 −6
Original line number Diff line number Diff line
@@ -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;
  }
+1 −1
Original line number Diff line number Diff line
@@ -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']);
+5 −4
Original line number Diff line number Diff line
@@ -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
+6 −6
Original line number Diff line number Diff line
@@ -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);

Loading