ContextProvidersPass.php 786 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Drupal\Core\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\ContainerBuilder;
  4. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  5. /**
  6. * Adds the context provider service IDs to the context manager.
  7. */
  8. class ContextProvidersPass implements CompilerPassInterface {
  9. /**
  10. * {@inheritdoc}
  11. *
  12. * Passes the service IDs of all context providers to the context repository.
  13. */
  14. public function process(ContainerBuilder $container) {
  15. $context_providers = [];
  16. foreach (array_keys($container->findTaggedServiceIds('context_provider')) as $id) {
  17. $context_providers[] = $id;
  18. }
  19. $definition = $container->getDefinition('context.repository');
  20. $definition->addArgument($context_providers);
  21. }
  22. }