From 0975b1fbf6fb73d06bf43c98fd7114f223f5e68d Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Thu, 24 Jan 2013 10:46:22 -0800 Subject: [PATCH] Issue #1894910 by sun: Move module_invoke() into ModuleHandler. --- core/includes/bootstrap.inc | 15 ++++++++++++ core/includes/module.inc | 24 ------------------- .../Drupal/Core/Extension/ModuleHandler.php | 11 +++++++++ .../Core/Extension/ModuleHandlerInterface.php | 15 ++++++++++++ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 676a94858745..fb399e4d80d9 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 83a3ba625ea2..d99b39dcf368 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 8e1cdb683338..14b4e7210395 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 7cb84186aafe..4fb9c8cfe64d 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. * -- GitLab