function HookCollectorPass::collectAllHookImplementations

Collects all hook implementations.

@internal This method is only used by ModuleHandler.

@todo Pass only $container and make protected when ModuleHandler::add() is removed in Drupal 12.0.0.

Parameters

array<string, array{pathname: string}> $module_list: An associative array. Keys are the module names, values are relevant info yml file path.

list<string> $skipProceduralModules: Module names that are known to not have procedural hook implementations.

Return value

static A HookCollectorPass instance holding all hook implementations and include file information.

2 calls to HookCollectorPass::collectAllHookImplementations()
HookCollectorPass::process in core/lib/Drupal/Core/Hook/HookCollectorPass.php
ModuleHandler::add in core/lib/Drupal/Core/Extension/ModuleHandler.php
Adds a module or profile to the list of currently active modules.

File

core/lib/Drupal/Core/Hook/HookCollectorPass.php, line 363

Class

HookCollectorPass
Collects and registers hook implementations.

Namespace

Drupal\Core\Hook

Code

public static function collectAllHookImplementations(array $module_list, array $skipProceduralModules = []) : static {
  $modules = array_keys($module_list);
  $modules_by_length = $modules;
  usort($modules_by_length, static fn($a, $b) => strlen($b) - strlen($a));
  $known_modules_pattern = implode('|', array_map(static fn($x) => preg_quote($x, '/'), $modules_by_length));
  $module_preg = '/^(?<function>(?<module>' . $known_modules_pattern . ')_(?!update_\\d)(?<hook>[a-zA-Z0-9_\\x80-\\xff]+$))/';
  $collector = new static($modules);
  foreach ($module_list as $module => $info) {
    $skip_procedural = in_array($module, $skipProceduralModules);
    $collector->collectModuleHookImplementations(dirname($info['pathname']), $module, $module_preg, $skip_procedural);
  }
  return $collector;
}

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