7 module.inc | module_invoke_all( |
4.6 module.inc | module_invoke_all() |
4.7 module.inc | module_invoke_all() |
5 module.inc | module_invoke_all() |
6 module.inc | module_invoke_all() |
8 bootstrap.inc | module_invoke_all($hook) |
Invokes a hook in all enabled modules that implement it.
All arguments are passed by value. Use drupal_alter() if you need to pass arguments by reference.
Parameters
$hook: The name of the hook to invoke.
...: Arguments to pass to the hook.
Return value
An array of return values of the hook implementations. If modules return arrays from their implementations, those are merged into one array.
See also
Related topics
146 calls to module_invoke_all()
- actions_delete in includes/
actions.inc - Deletes a single action from the database.
- actions_list in includes/
actions.inc - Discovers all available actions by invoking hook_action_info().
- aggregator_remove in modules/
aggregator/ aggregator.module - Removes all items from a feed.
- ajax_footer in includes/
ajax.inc - Performs end-of-Ajax-request tasks.
- archiver_get_info in includes/
common.inc - Retrieves a list of all available archivers.
File
- includes/
module.inc, line 890 - API for loading and interacting with Drupal modules.
Code
function module_invoke_all($hook) {
$args = func_get_args();
// Remove $hook from the arguments.
unset($args[0]);
$return = array();
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
$result = call_user_func_array($function, $args);
if (isset($result) && is_array($result)) {
$return = array_merge_recursive($return, $result);
}
elseif (isset($result)) {
$return[] = $result;
}
}
}
return $return;
}
Comments
Pass by reference
Unfortunately this function and module_invoke() do not allow passing variables by reference.
To work around this, you can do something like this:
<?php
foreach (module_implements('my_hook') as $module) {
$function = $module . '_my_hook';
$function($var1, $var2);
}
?>
And, make sure to have the ampersand in the hook declaration:
<?php
function my_module_my_hook(&$var1, &$var2) {
$var1 = 'do';
$var2 = 'stuff';
}
?>
drupal_alter()?
If you want to pass things by reference, it's likely that you want to do
<?php
$modified_data = drupal_alter('my_type', $data);
?>
instead.
http://api.drupal.org/api/drupal/includes!module.inc/function/drupal_alt...