You are here

PreprocessEventPass.php in Hook Event Dispatcher 8

File

src/Service/PreprocessEventPass.php
View source
<?php

namespace Drupal\hook_event_dispatcher\Service;

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

/**
 * Class PreprocessEventPass.
 */
final class PreprocessEventPass implements CompilerPassInterface {

  /**
   * Add the PreprocessEventFactories to the PreprocessEventFactoryMapper.
   *
   * First get the factory defaults and then append the new/overrides to them.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
   *   Drupal container.
   */
  public function process(ContainerBuilder $container) {
    $factoryMapper = $container
      ->getDefinition('preprocess_event.factory_mapper');
    $factoryIds = $container
      ->findTaggedServiceIds('preprocess_event_default_factory');
    $factoryIds += $container
      ->findTaggedServiceIds('preprocess_event_factory');
    foreach (\array_keys($factoryIds) as $id) {
      $factoryMapper
        ->addMethodCall('addFactory', [
        new Reference($id),
      ]);
    }
  }

}

Classes

Namesort descending Description
PreprocessEventPass Class PreprocessEventPass.