Skip to content

Instantly share code, notes, and snippets.

@drupler
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drupler/ddb577569864cbccdc8e to your computer and use it in GitHub Desktop.
Save drupler/ddb577569864cbccdc8e to your computer and use it in GitHub Desktop.
<?php
/**
* Invokes a hook in all enabled modules that implement it.
*
* @param $hook
* The name of the hook to invoke.
* @param ...
* Arguments to pass to the hook.
*
* @return
* An array of return values of the hook implementations. If modules return
* arrays from their implementations, those are merged into one array.
*/
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) {
// BEGIN CRON LOG
if ($hook == "cron") {
watchdog('cron', 'Running cron for: %module', array('%module' => $module), WATCHDOG_NOTICE);
}
// END CRON LOG
$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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment