7 module.inc | module_load_include($type, $module, $name = NULL) |
6 module.inc | module_load_include($type, $module, $name = NULL) |
8 module.inc | module_load_include($type, $module, $name = NULL) |
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
The name of the included file, if successful; FALSE otherwise.
- dashboard_admin_blocks in modules/
dashboard/ dashboard.module - Page callback: Builds the page for administering dashboard blocks.
- field_modules_uninstalled in modules/
field/ field.module - Implements hook_modules_uninstalled().
- form_get_cache in includes/
form.inc - Fetches a form from cache.
- form_load_include in includes/
form.inc - Ensures an include file is loaded whenever the form is processed.
- forum_overview in modules/
forum/ forum.admin.inc - Form constructor for the forum overview form.
File
- includes/
module.inc, line 322 - API for loading and interacting with Drupal modules.
Code
function module_load_include($type, $module, $name = NULL) {
if (!isset($name)) {
$name = $module;
}
if (function_exists('drupal_get_path')) {
$file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
if (is_file($file)) {
require_once $file;
return $file;
}
}
return FALSE;
}
Comments
Subdirectory includes
For subdirectory includes, see http://api.drupal.org/api/drupal/includes%21module.inc/function/module_l....
Impossible restriction
I don't see how this can apply to module or theme developers because they do not know the path to the file (e.g. sites/SITENAME/modules/...). The choices would appear to be either a relative include path, a path derived from dirname(__FILE__), or drupal_get_path, or something that calls drupal_get_path (such as this function).
Confused between this function and .info file
For the case of loading files w/in a module (i.e. other inc files), why would we use this over the files[] defined in the .info file? Isn't the dynamic class/file loader specified by files[] a better alternative?
Class and interface declarations
My current understanding is that you would use the files[] syntax in your info file if you were declaring class or interface functionality in your .inc file.
If you require to call functions, then the module_load_include is required.
as per http://drupal.org/node/1762288#comment-6749026
use drupal_load() to load a
use drupal_load() to load a .module file
http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupa...
drupal_load('module', 'browscap');