diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 676a94858745614fdd5c4c82221e8606d6e6da9d..fb399e4d80d90466807ddf72bee625df81b54cb8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -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. * diff --git a/core/includes/module.inc b/core/includes/module.inc index 83a3ba625ea2349d9241a24fbb59333787bd84e4..d99b39dcf368a786dff979a4d881b20e49006db2 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -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". */ diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 8e1cdb683338ed03d0edef2ff1822cb603f416b5..14b4e7210395e6037bb1208cc97d8d6f5b0f9fcd 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -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(). */ diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index 7cb84186aafeaf5d58763bfe117248ef9d0eda59..4fb9c8cfe64dae640aabc575bd820a8d533f2442 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -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. *