Last active
August 29, 2015 14:16
-
-
Save drupler/ddb577569864cbccdc8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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