5 module.inc | module_invoke() |
6 module.inc | module_invoke() |
7 module.inc | module_invoke($module, $hook) |
8 module.inc | module_invoke($module, $hook) |
Invoke a hook in a particular module.
Parameters
$module: The name of the module (without the .module extension).
$hook: The name of the hook to invoke.
...: Arguments to pass to the hook implementation.
Return value
The return value of the hook implementation.
Related topics
53 calls to module_invoke()
1 string reference to 'module_invoke'
File
- includes/
module.inc, line 469 - API for loading and interacting with Drupal modules.
Code
function module_invoke() {
$args = func_get_args();
$module = $args[0];
$hook = $args[1];
unset($args[0], $args[1]);
$function = $module . '_' . $hook;
if (module_hook($module, $hook)) {
return call_user_func_array($function, $args);
}
}
Login or register to post comments
Comments
Args Not Passed By Reference
It is useful to realize that the args passed to invoked functions are not passed by reference with calls to module_invoke() (or to module_invoke_all(), for that matter).
Possible solution
PHP 5.3 (5.2?), changed the way that call_user_func_array() treats args passed by reference.
Here's how I've modified module_invoke() to deal with this:
<?php
function module_invoke() {
$args = func_get_args();
$module = $args[0];
$hook = $args[1];
unset($args[0], $args[1]);
$function = $module . '_' . $hook;
if (module_hook($module, $hook)) {
if (strnatcmp(phpversion(),'5.2') <= 0)
return call_user_func_array($function, $args);
else {
$ref_args = array();
foreach ($args as $key => &$arg) {
$ref_args[$key] = &$arg;
}
return call_user_func_array($function, $ref_args);
}
}
}
?>
The function module_invoke_all() needs a similar change.
[Follow-up:] This is not actually a good fix. See http://drupal.org/node/353494
Placing blocks
http://drupal.org/node/26502