Same name and namespace in other branches
  1. 4.7.x includes/module.inc \module_invoke_all()
  2. 5.x includes/module.inc \module_invoke_all()
  3. 6.x includes/module.inc \module_invoke_all()
  4. 7.x includes/module.inc \module_invoke_all()

Invoke a hook in all enabled modules that implement it.

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.

Related topics

27 calls to module_invoke_all()
comment_moderate in modules/comment.module
comment_post in modules/comment.module
comment_preview in modules/comment.module
comment_render in modules/comment.module
comment_save in modules/comment.module

... See full list

File

includes/module.inc, line 195
API for loading and interacting with Drupal modules.

Code

function module_invoke_all() {
  $args = func_get_args();
  $hook = array_shift($args);
  $return = array();
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    $result = call_user_func_array($function, $args);
    if (is_array($result)) {
      $return = array_merge($return, $result);
    }
    else {
      if (isset($result)) {
        $return[] = $result;
      }
    }
  }
  return $return;
}