You are here

public function Target::executeHook in Drupal 7 to 8/9 Module Upgrader 8

Executes a hook implementation and returns the result.

Parameters

string $hook: The hook to execute, without the hook_ prefix.

array $arguments: Additional parameters to pass to the hook implementation.

Return value

mixed

Throws

\InvalidArgumentException if the module doesn't implement the hook. \LogicException if the hook contains non-executable logic.

Overrides TargetInterface::executeHook

File

src/Target.php, line 193

Class

Target
Default implementation of TargetInterface.

Namespace

Drupal\drupalmoduleupgrader

Code

public function executeHook($hook, array $arguments = []) {
  if ($this
    ->implementsHook($hook)) {
    return $this
      ->getIndexer('function')
      ->execute('hook_' . $hook, $arguments);
  }
  else {
    $variables = [
      '@module' => $this
        ->id(),
      '@hook' => $hook,
    ];
    throw new \InvalidArgumentException((new FormattableMarkup('@module does not implement hook_@hook.', $variables))
      ->__toString());
  }
}