function ModuleHandler::legacyInvoke

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::legacyInvoke()

Calls a function called $module . '_' . $hook if one exists.

Parameters

string $module: The name of the module (without the .module extension).

string $hook: The name of the hook to invoke.

array $args: Arguments to pass to the hook implementation.

Return value

mixed The return value of the hook implementation.

File

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

Class

ModuleHandler
Class that manages modules in a Drupal installation.

Namespace

Drupal\Core\Extension

Code

protected function legacyInvoke($module, $hook, array $args = []) {
  $this->load($module);
  $function = $module . '_' . $hook;
  if (function_exists($function) && !(new \ReflectionFunction($function))->getAttributes(LegacyHook::class)) {
    return $function(...$args);
  }
  return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.