function DevelHookCommand::getImplementations

Finds the implementations of a hook.

Return value

array<string, array{module: string, name: string, file: string, line: int}> The implementations, keyed by function or Class::method name.

2 calls to DevelHookCommand::getImplementations()
DevelHookCommand::askForImplementation in src/Command/DevelHookCommand.php
Prompts for an implementation when none was given.
DevelHookCommand::__invoke in src/Command/DevelHookCommand.php
Lists the implementations of a hook, or opens one of them in an editor.

File

src/Command/DevelHookCommand.php, line 103

Class

DevelHookCommand
Lists the implementations of a hook and opens one in an editor.

Namespace

Drupal\devel\Command

Code

protected function getImplementations(string $hook) : array {
  $listeners = [];
  // Despite its name, invokeAllWith() only passes each implementation to the
  // callback. The hooks are collected here, never run.
  $this->moduleHandler
    ->invokeAllWith($hook, static function (callable $listener, string $module) use (&$listeners) : void {
    $listeners[] = [
      $module,
      $listener,
    ];
  });
  // Hooks in .install files, such as hook_install() and hook_update_N(), are
  // not registered as implementations. Find those by function name.
  include_once DRUPAL_ROOT . '/core/includes/install.inc';
  drupal_load_updates();
  foreach (array_keys($this->moduleHandler
    ->getModuleList()) as $module) {
    if (function_exists($module . '_' . $hook)) {
      $listeners[] = [
        $module,
        $module . '_' . $hook,
      ];
    }
  }
  $implementations = [];
  foreach ($listeners as [$module, $listener]) {
    $location = $this->locate($listener);
    $implementations[$location['name']] ??= [
      'module' => $module,
    ] + $location;
  }
  return $implementations;
}