class RegisterEventSubscribersPass

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php \Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass
  2. 8.9.x core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php \Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass
  3. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php \Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass

Wraps the Symfony event subscriber pass to use different tag names.

Hierarchy

  • class \Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

Expanded class hierarchy of RegisterEventSubscribersPass

1 file declares its use of RegisterEventSubscribersPass
CoreServiceProvider.php in core/lib/Drupal/Core/CoreServiceProvider.php

File

core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php, line 12

Namespace

Drupal\Core\DependencyInjection\Compiler
View source
class RegisterEventSubscribersPass implements CompilerPassInterface {
    
    /**
     * Constructs a RegisterEventSubscribersPass object.
     *
     * @param \Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass $pass
     *   The Symfony compiler pass that registers event subscribers.
     */
    public function __construct(RegisterListenersPass $pass) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container) : void {
        $this->renameTag($container, 'event_subscriber', 'kernel.event_subscriber');
        $this->pass
            ->process($container);
        $this->renameTag($container, 'kernel.event_subscriber', 'event_subscriber');
    }
    
    /**
     * Renames tags in the container.
     *
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
     *   The container.
     * @param string $source_tag
     *   The tag to be renamed.
     * @param string $target_tag
     *   The tag to rename with.
     */
    protected function renameTag(ContainerBuilder $container, string $source_tag, string $target_tag) : void {
        foreach ($container->getDefinitions() as $definition) {
            if ($definition->hasTag($source_tag)) {
                $attributes = $definition->getTag($source_tag)[0];
                $definition->addTag($target_tag, $attributes);
                $definition->clearTag($source_tag);
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
RegisterEventSubscribersPass::process public function
RegisterEventSubscribersPass::renameTag protected function Renames tags in the container.
RegisterEventSubscribersPass::__construct public function Constructs a RegisterEventSubscribersPass object.

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