ContextProvidersPass.php

Same filename in other branches
  1. 8.9.x core/lib/Drupal/Core/DependencyInjection/Compiler/ContextProvidersPass.php
  2. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/ContextProvidersPass.php

Namespace

Drupal\Core\DependencyInjection\Compiler

File

core/lib/Drupal/Core/DependencyInjection/Compiler/ContextProvidersPass.php

View source
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
 * Adds the context provider service IDs to the context manager.
 */
class ContextProvidersPass implements CompilerPassInterface {
    
    /**
     * {@inheritdoc}
     *
     * Passes the service IDs of all context providers to the context repository.
     */
    public function process(ContainerBuilder $container) {
        $context_providers = [];
        foreach (array_keys($container->findTaggedServiceIds('context_provider')) as $id) {
            $context_providers[] = $id;
        }
        $definition = $container->getDefinition('context.repository');
        $definition->addArgument($context_providers);
    }

}

Classes

Title Deprecated Summary
ContextProvidersPass Adds the context provider service IDs to the context manager.

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