function HookCollectorPass::writeImplementationsToContainer
Writes all implementations to the container.
Parameters
\Symfony\Component\DependencyInjection\ContainerBuilder $container: The container builder.
array<string, array<string, string>> $implementationsByHook: Implementations, as module names keyed by hook name and "$class::$method" identifier.
1 call to HookCollectorPass::writeImplementationsToContainer()
- HookCollectorPass::writeToContainer in core/
lib/ Drupal/ Core/ Hook/ HookCollectorPass.php - Writes collected definitions to the container builder.
File
-
core/
lib/ Drupal/ Core/ Hook/ HookCollectorPass.php, line 307
Class
- HookCollectorPass
- Collects and registers hook implementations.
Namespace
Drupal\Core\HookCode
protected static function writeImplementationsToContainer(ContainerBuilder $container, array $implementationsByHook) : void {
$map = [];
$tagsInfoByClass = [];
foreach ($implementationsByHook as $hook => $hookImplementations) {
$priority = 0;
foreach ($hookImplementations as $class_and_method => $module) {
[
$class,
$method,
] = explode('::', $class_and_method);
$tagsInfoByClass[$class][] = [
'event' => "drupal_hook.{$hook}",
'method' => $method,
'priority' => $priority,
];
--$priority;
$map[$hook][$class][$method] = $module;
}
}
foreach ($tagsInfoByClass as $class => $tagsInfo) {
if ($container->hasDefinition($class)) {
$definition = $container->findDefinition($class);
}
else {
$definition = $container->register($class, $class)
->setAutowired(TRUE);
}
foreach ($tagsInfo as $tag_info) {
$definition->addTag('kernel.event_listener', $tag_info);
}
}
$container->setParameter('hook_implementations_map', $map);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.