Commit 0975b1fb authored by webchick's avatar webchick
Browse files

Issue #1894910 by sun: Move module_invoke() into ModuleHandler.

parent 2215dc2e
......@@ -2515,6 +2515,21 @@ function module_implements($hook) {
return drupal_container()->get('module_handler')->getImplementations($hook);
}
/**
* Invokes a hook in a particular module.
*
* @deprecated as of Drupal 8.0. Use
* drupal_container()->get('module_handler')->invoke($module, $hook, $args = array()).
*
* @see \Drupal\Core\Extension\ModuleHandler::invoke()
*/
function module_invoke($module, $hook) {
$args = func_get_args();
// Remove $module and $hook from the arguments.
unset($args[0], $args[1]);
return drupal_container()->get('module_handler')->invoke($module, $hook, $args);
}
/**
* Invokes a hook in all enabled modules that implement it.
*
......
......@@ -623,31 +623,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE)
* are executed when running Drupal.
*
* See also @link themeable the themeable group page. @endlink
*/
/**
* Invokes a hook in a particular module.
*
* @param $module
* The name of the module (without the .module extension).
* @param $hook
* The name of the hook to invoke.
* @param ...
* Arguments to pass to the hook implementation.
*
* @return
* The return value of the hook implementation.
*/
function module_invoke($module, $hook) {
$args = func_get_args();
// Remove $module and $hook from the arguments.
unset($args[0], $args[1]);
if (module_hook($module, $hook)) {
return call_user_func_array($module . '_' . $hook, $args);
}
}
/**
* @} End of "defgroup hooks".
*/
......
......@@ -258,6 +258,17 @@ public function implementsHook($module, $hook) {
return FALSE;
}
/**
* Implements \Drupal\Core\Extension\ModuleHandlerInterface::invoke().
*/
public function invoke($module, $hook, $args = array()) {
if (!$this->implementsHook($module, $hook)) {
return;
}
$function = $module . '_' . $hook;
return call_user_func_array($function, $args);
}
/**
* Implements \Drupal\Core\Extension\ModuleHandlerInterface::invokeAll().
*/
......
......@@ -170,6 +170,21 @@ public function resetImplementations();
*/
public function implementsHook($module, $hook);
/**
* Invokes a hook in a particular module.
*
* @param string $module
* The name of the module (without the .module extension).
* @param string $hook
* The name of the hook to invoke.
* @param ...
* Arguments to pass to the hook implementation.
*
* @return mixed
* The return value of the hook implementation.
*/
public function invoke($module, $hook, $args = array());
/**
* Invokes a hook in all enabled modules that implement it.
*
......
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