function TaggedHandlersPass::processServiceIdCollectorPass

Same name in other branches
  1. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php \Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass::processServiceIdCollectorPass()
  2. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php \Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass::processServiceIdCollectorPass()
  3. 11.x core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php \Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass::processServiceIdCollectorPass()

Processes a service collector ID service pass.

Parameters

array $pass: The service collector pass data.

string $consumer_id: The consumer service ID.

\Symfony\Component\DependencyInjection\ContainerBuilder $container: The service container.

1 call to TaggedHandlersPass::processServiceIdCollectorPass()
TaggedHandlersPass::process in core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php
Finds services tagged with 'service_collector' or 'service_id_collector', then finds all corresponding tagged services.

File

core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php, line 212

Class

TaggedHandlersPass
Collects services to add/inject them into a consumer service.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

protected function processServiceIdCollectorPass(array $pass, $consumer_id, ContainerBuilder $container) {
    $tag = isset($pass['tag']) ? $pass['tag'] : $consumer_id;
    $required = isset($pass['required']) ? $pass['required'] : FALSE;
    $consumer = $container->getDefinition($consumer_id);
    // Find all tagged handlers.
    $handlers = [];
    foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) {
        $handlers[$id] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
    }
    if ($required && empty($handlers)) {
        throw new LogicException(sprintf("At least one service tagged with '%s' is required.", $tag));
    }
    // Sort all handlers by priority.
    arsort($handlers, SORT_NUMERIC);
    $consumer->addArgument(array_keys($handlers));
}

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