public function ModuleHandler::implementsHook in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::implementsHook()
Returns whether a given module implements a given hook.
Parameters
string $module: The name of the module (without the .module extension).
string $hook: The name of the hook (e.g. "help" or "menu").
Return value
bool TRUE if the module is both installed and enabled, and the hook is implemented in that module.
Overrides ModuleHandlerInterface::implementsHook
1 call to ModuleHandler::implementsHook()
- ModuleHandler::invoke in core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php - Invokes a hook in a particular module.
File
- core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php, line 367
Class
- ModuleHandler
- Class that manages modules in a Drupal installation.
Namespace
Drupal\Core\ExtensionCode
public function implementsHook($module, $hook) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
return TRUE;
}
// If the hook implementation does not exist, check whether it lives in an
// optional include file registered via hook_hook_info().
$hook_info = $this
->getHookInfo();
if (isset($hook_info[$hook]['group'])) {
$this
->loadInclude($module, 'inc', $module . '.' . $hook_info[$hook]['group']);
if (function_exists($function)) {
return TRUE;
}
}
return FALSE;
}