Commit 456fd7cc authored by Dries's avatar Dries
Browse files

- Patch #17770 by chx: fixed module_invoke() and module_invoke_all() not to...

- Patch #17770 by chx: fixed module_invoke() and module_invoke_all() not to use NULL defaults (bugfix) + removed the limitation on the number of paramaters that can be used.
parent 84268b3a
...@@ -172,13 +172,15 @@ function module_implements($hook) { ...@@ -172,13 +172,15 @@ function module_implements($hook) {
* @return * @return
* The return value of the hook implementation. * The return value of the hook implementation.
*/ */
function module_invoke($module, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) { function module_invoke() {
$args = func_get_args();
$module = array_shift($args);
$hook = array_shift($args);
$function = $module .'_'. $hook; $function = $module .'_'. $hook;
if (function_exists($function)) { if (module_hook($module, $hook)) {
return $function($a1, $a2, $a3, $a4); return call_user_func_array($function, $args);
} }
} }
/** /**
* Invoke a hook in all enabled modules that implement it. * Invoke a hook in all enabled modules that implement it.
* *
...@@ -190,10 +192,13 @@ function module_invoke($module, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = ...@@ -190,10 +192,13 @@ function module_invoke($module, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 =
* An array of return values of the hook implementations. If modules return * An array of return values of the hook implementations. If modules return
* arrays from their implementations, those are merged into one array. * arrays from their implementations, those are merged into one array.
*/ */
function module_invoke_all($hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) { function module_invoke_all() {
$args = func_get_args();
$hook = array_shift($args);
$return = array(); $return = array();
foreach (module_list() as $module) { foreach (module_implements($hook) as $module) {
$result = module_invoke($module, $hook, $a1, $a2, $a3, $a4); $function = $module .'_'. $hook;
$result = call_user_func_array($function, $args);
if (is_array($result)) { if (is_array($result)) {
$return = array_merge($return, $result); $return = array_merge($return, $result);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment