function HookCollectorPass::writeToContainer
Writes collected definitions to the container builder.
Parameters
\Symfony\Component\DependencyInjection\ContainerBuilder $container: Container builder.
File
-
core/
lib/ Drupal/ Core/ Hook/ HookCollectorPass.php, line 148
Class
- HookCollectorPass
- Collects and registers hook implementations.
Namespace
Drupal\Core\HookCode
protected function writeToContainer(ContainerBuilder $container) : void {
$container->register(ProceduralCall::class, ProceduralCall::class)
->addArgument($this->includes);
// Gather includes for each hook_hook_info group. Store this in
// $groupIncludes so the module handler includes the files at runtime when
// the hooks are invoked.
$groupIncludes = [];
foreach ($this->hookInfo as $function) {
foreach ($function() as $hook => $info) {
if (isset($this->groupIncludes[$info['group']])) {
$groupIncludes[$hook] = $this->groupIncludes[$info['group']];
}
}
}
$implementationsByHook = $this->calculateImplementations();
static::writeImplementationsToContainer($container, $implementationsByHook);
$container->setParameter('preprocess_for_suggestions', $this->preprocessForSuggestions ?? []);
// Update the module handler definition.
$definition = $container->getDefinition('module_handler');
$definition->setArgument('$groupIncludes', $groupIncludes);
$packed_order_operations = [];
$order_operations = $this->getOrderOperations();
foreach (preg_grep('@_alter$@', array_keys($order_operations)) as $alter_hook) {
$packed_order_operations[$alter_hook] = array_map(fn(OrderOperation $operation) => $operation->pack(), $order_operations[$alter_hook]);
}
$definition->setArgument('$packedOrderOperations', $packed_order_operations);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.