Summary
The function module_load_install($module) is deprecated in Drupal 9.4.x and will be removed before Drupal 10.0.0. This function is currently found in core/includes/module.inc.
It is replaced by ModuleHandler::loadInclude($module, 'install'). The arguments and return values are unchanged. See \Drupal\Core\Extension\ModuleHandler
Before
module_load_install($module)
After
In procedural code:
\Drupal::moduleHandler()->loadInclude($module, 'install');
In OO code:
Inject the module_handler service and invoke the loadInclude($module, 'install') method on the injected service instead of using the static \Drupal::moduleHandler() call.
Note that the module handler (by design) only deals with installed modules, so in case you need to load the install file of an uninstalled module, the above does not work. Instead you need to do:
$moduleExtensionList = \Drupal::service('extension.list.module');
assert($moduleExtensionList instanceof ModuleExtensionList);
$modulePath = $moduleExtensionList->getPath($module);
$moduleInstallPath = \Drupal::root() . '/' . $modulePath . "/$module.install";
if (is_file($moduleInstallPath)) {
require_once $moduleInstallPath;
}
Note that this should only be done in rare cases, when it cannot be avoided. If you need code of another module (even if "just" from the install file), usually the better option is to declare a dependency on that module and then use the module handler as explained above.
Comments
Documentation above is partially incorrect
The "After" code remediation instructions are incorrect. These should read:
After
In procedural code:
\Drupal::moduleHandler()->loadInclude($module, 'install');In OO code:
Inject the
module_handlerservice and invoke theloadInclude($module, 'install')method on the injected service instead of using the static\Drupal::moduleHandler()call.Lisa Ridley
Product Manager / Tech Team Manager
PlanLeft LLC
https://www.planleft.com