function HookCollectorPass::process
File
-
core/
lib/ Drupal/ Core/ Hook/ HookCollectorPass.php, line 75
Class
- HookCollectorPass
- Collects and registers hook implementations.
Namespace
Drupal\Core\HookCode
public function process(ContainerBuilder $container) : void {
$collector = static::collectAllHookImplementations($container->getParameter('container.modules'));
$map = [];
$container->register(ProceduralCall::class, ProceduralCall::class)
->addArgument($collector->includes);
$groupIncludes = [];
foreach ($collector->hookInfo as $function) {
foreach ($function() as $hook => $info) {
if (isset($collector->groupIncludes[$info['group']])) {
$groupIncludes[$hook] = $collector->groupIncludes[$info['group']];
}
}
}
$definition = $container->getDefinition('module_handler');
$definition->setArgument('$groupIncludes', $groupIncludes);
foreach ($collector->moduleImplements as $hook => $moduleImplements) {
foreach ($collector->moduleImplementsAlters as $alter) {
$alter($moduleImplements, $hook);
}
$priority = 0;
foreach ($moduleImplements as $module => $v) {
foreach ($collector->implementations[$hook][$module] as $class => $method_hooks) {
if ($container->has($class)) {
$definition = $container->findDefinition($class);
}
else {
$definition = $container->register($class, $class)
->setAutowired(TRUE);
}
foreach ($method_hooks as $method) {
$map[$hook][$class][$method] = $module;
$definition->addTag('kernel.event_listener', [
'event' => "drupal_hook.{$hook}",
'method' => $method,
'priority' => $priority--,
]);
}
}
}
}
$container->setParameter('hook_implementations_map', $map);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.