ModuleHandler::implementsHook

public ModuleHandler::implementsHook($module, $hook)

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

File

core/lib/Drupal/Core/Extension/ModuleHandler.php, line 366

Class

ModuleHandler
Class that manages modules in a Drupal installation.

Namespace

Drupal\Core\Extension

Code

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;
}
doc_Drupal
2016-10-29 09:29:15
Comments
Leave a Comment

Please login to continue.