function module_load_include
Same name in other branches
- 7.x includes/module.inc \module_load_include()
- 8.9.x core/includes/module.inc \module_load_include()
- 10 core/includes/module.inc \module_load_include()
Loads a module include file.
Examples:
// Load node.admin.inc from the node module.
module_load_include('inc', 'node', 'node.admin');
// Load content_types.inc from the node module.
module_load_include('inc', 'node', 'content_types');
Do not use this function to load an install file, use module_load_install() instead. Do not use this function in a global context since it requires Drupal to be fully bootstrapped, use require_once DRUPAL_ROOT . '/path/file' instead.
Parameters
$type: The include file's type (file extension).
$module: The module to which the include file belongs.
$name: (optional) The base file name (without the $type extension). If omitted, $module is used; i.e., resulting in "$module.$type" by default.
Return value
bool|string The name of the included file, if successful; FALSE otherwise.
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 also
https://www.drupal.org/node/2948698
1 call to module_load_include()
- ModuleLegacyTest::testModuleLoadInclude in core/
tests/ Drupal/ KernelTests/ Core/ Extension/ ModuleLegacyTest.php - Test deprecation of module_load_include() function.
File
-
core/
includes/ module.inc, line 76
Code
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;
}
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) . "/{$name}.{$type}";
if (is_file($file)) {
require_once $file;
return $file;
}
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.