Skip to content
Snippets Groups Projects
Verified Commit 9dbd2a6b authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2909185 by longwave, donquixote, andypost, andregp, pounard, jibran,...

Issue #2909185 by longwave, donquixote, andypost, andregp, pounard, jibran, martin107, kostyashupenko, catch, znerol: Replace ContainerAwareEventDispatcher with Symfony EventDispatcher
parent 1f1d1ab3
Branches
Tags
32 merge requests!12227Issue #3181946 by jonmcl, mglaman,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!213Issue #2906496: Give Media a menu item under Content
Pipeline #132498 passed with warnings
Pipeline: drupal

#132501

    ......@@ -871,8 +871,7 @@ services:
    arguments: ['@request_stack']
    Drupal\Core\Routing\RouteMatchInterface: '@current_route_match'
    event_dispatcher:
    class: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
    arguments: ['@service_container']
    class: Symfony\Component\EventDispatcher\EventDispatcher
    Psr\EventDispatcher\EventDispatcherInterface: '@event_dispatcher'
    Symfony\Contracts\EventDispatcher\EventDispatcherInterface: '@event_dispatcher'
    controller_resolver:
    ......
    ......@@ -2,6 +2,8 @@
    namespace Drupal\Component\EventDispatcher;
    @trigger_error('The ' . __NAMESPACE__ . '\ContainerAwareEventDispatcher is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use Symfony\Component\EventDispatcher\EventDispatcher instead. See https://www.drupal.org/node/3376090', E_USER_DEPRECATED);
    use Psr\EventDispatcher\StoppableEventInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    ......@@ -30,6 +32,11 @@
    * runtime is not affected by this change though.
    * </dd>
    * </dl>
    *
    * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
    * \Symfony\Component\EventDispatcher\EventDispatcher instead.
    *
    * @see https://www.drupal.org/node/3376090
    */
    class ContainerAwareEventDispatcher implements EventDispatcherInterface {
    ......
    ......@@ -30,6 +30,7 @@
    use Psr\Log\LoggerAwareInterface;
    use Symfony\Component\DependencyInjection\Compiler\PassConfig;
    use Symfony\Component\DependencyInjection\Reference;
    use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    /**
    ......@@ -83,7 +84,7 @@ public function register(ContainerBuilder $container) {
    $container->addCompilerPass(new TwigExtensionPass());
    // Add a compiler pass for registering event subscribers.
    $container->addCompilerPass(new RegisterEventSubscribersPass(), PassConfig::TYPE_AFTER_REMOVING);
    $container->addCompilerPass(new RegisterEventSubscribersPass(new RegisterListenersPass()), PassConfig::TYPE_AFTER_REMOVING);
    $container->addCompilerPass(new LoggerAwarePass(), PassConfig::TYPE_AFTER_REMOVING);
    $container->addCompilerPass(new RegisterAccessChecksPass());
    ......
    ......@@ -4,59 +4,50 @@
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
    /**
    * Registers all event subscribers to the event dispatcher.
    * Wraps the Symfony event subscriber pass to use different tag names.
    */
    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(
    protected RegisterListenersPass $pass
    ) {}
    /**
    * {@inheritdoc}
    */
    public function process(ContainerBuilder $container): void {
    if (!$container->hasDefinition('event_dispatcher')) {
    return;
    $this->renameTag($container, 'event_subscriber', 'kernel.event_subscriber');
    $this->pass->process($container);
    $this->renameTag($container, 'kernel.event_subscriber', 'event_subscriber');
    }
    $definition = $container->getDefinition('event_dispatcher');
    $event_subscriber_info = [];
    foreach ($container->findTaggedServiceIds('event_subscriber') as $id => $attributes) {
    // We must assume that the class value has been correctly filled, even if
    // the service is created by a factory.
    $class = $container->getDefinition($id)->getClass();
    $interface = EventSubscriberInterface::class;
    if (!is_subclass_of($class, $interface)) {
    throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
    }
    // Get all subscribed events.
    foreach ($class::getSubscribedEvents() as $event_name => $params) {
    if (is_string($params)) {
    $priority = 0;
    $event_subscriber_info[$event_name][$priority][] = ['service' => [$id, $params]];
    }
    elseif (is_string($params[0])) {
    $priority = $params[1] ?? 0;
    $event_subscriber_info[$event_name][$priority][] = ['service' => [$id, $params[0]]];
    }
    else {
    foreach ($params as $listener) {
    $priority = $listener[1] ?? 0;
    $event_subscriber_info[$event_name][$priority][] = ['service' => [$id, $listener[0]]];
    }
    }
    }
    /**
    * 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);
    }
    foreach (array_keys($event_subscriber_info) as $event_name) {
    krsort($event_subscriber_info[$event_name]);
    }
    $definition->addArgument($event_subscriber_info);
    }
    }
    ......@@ -4,7 +4,6 @@
    namespace Drupal\Tests\layout_builder\Unit;
    use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
    use Drupal\Component\Plugin\Exception\PluginException;
    use Drupal\Core\Access\AccessResult;
    use Drupal\Core\Block\BlockManagerInterface;
    ......@@ -24,6 +23,7 @@
    use Drupal\layout_builder\SectionComponent;
    use Drupal\Tests\UnitTestCase;
    use Prophecy\Argument;
    use Symfony\Component\EventDispatcher\EventDispatcher;
    /**
    * @coversDefaultClass \Drupal\layout_builder\Section
    ......@@ -62,7 +62,7 @@ class SectionRenderTest extends UnitTestCase {
    /**
    * The event dispatcher.
    *
    * @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
    * @var \Symfony\Component\EventDispatcher\EventDispatcher
    */
    protected $eventDispatcher;
    ......@@ -77,7 +77,7 @@ protected function setUp(): void {
    $this->contextHandler = $this->prophesize(ContextHandlerInterface::class);
    $this->contextRepository = $this->prophesize(ContextRepositoryInterface::class);
    // @todo Refactor this into some better tests in https://www.drupal.org/node/2942605.
    $this->eventDispatcher = (new \ReflectionClass(ContainerAwareEventDispatcher::class))->newInstanceWithoutConstructor();
    $this->eventDispatcher = (new \ReflectionClass(EventDispatcher::class))->newInstanceWithoutConstructor();
    $this->account = $this->prophesize(AccountInterface::class);
    $subscriber = new BlockComponentRenderArray($this->account->reveal());
    ......
    ......@@ -25,6 +25,7 @@
    * synchronizations.
    *
    * @group EventDispatcher
    * @group legacy
    */
    class ContainerAwareEventDispatcherTest extends TestCase {
    ......
    ......@@ -4,13 +4,13 @@
    namespace Drupal\Tests\Core\EventSubscriber;
    use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher as EventDispatcher;
    use Drupal\Core\EventSubscriber\RedirectResponseSubscriber;
    use Drupal\Core\Routing\TrustedRedirectResponse;
    use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
    use Drupal\Tests\UnitTestCase;
    use Psr\Log\LoggerInterface;
    use Symfony\Component\DependencyInjection\Container;
    use Symfony\Component\EventDispatcher\EventDispatcher;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpKernel\Event\ResponseEvent;
    ......@@ -87,7 +87,7 @@ protected function setUp(): void {
    * @dataProvider providerTestDestinationRedirect
    */
    public function testDestinationRedirect(Request $request, $expected) {
    $dispatcher = new EventDispatcher(\Drupal::getContainer());
    $dispatcher = new EventDispatcher();
    $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $response = new RedirectResponse('http://example.com/drupal');
    $request->headers->set('HOST', 'example.com');
    ......@@ -128,7 +128,7 @@ public static function providerTestDestinationRedirect() {
    * @dataProvider providerTestDestinationRedirectToExternalUrl
    */
    public function testDestinationRedirectToExternalUrl($request, $expected) {
    $dispatcher = new EventDispatcher(\Drupal::getContainer());
    $dispatcher = new EventDispatcher();
    $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $response = new RedirectResponse('http://other-example.com');
    ......@@ -143,7 +143,7 @@ public function testDestinationRedirectToExternalUrl($request, $expected) {
    * @covers ::checkRedirectUrl
    */
    public function testRedirectWithOptInExternalUrl() {
    $dispatcher = new EventDispatcher(\Drupal::getContainer());
    $dispatcher = new EventDispatcher();
    $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $response = new TrustedRedirectResponse('http://external-url.com');
    $request = Request::create('');
    ......@@ -176,7 +176,7 @@ public static function providerTestDestinationRedirectToExternalUrl() {
    * @dataProvider providerTestDestinationRedirectWithInvalidUrl
    */
    public function testDestinationRedirectWithInvalidUrl(Request $request) {
    $dispatcher = new EventDispatcher(\Drupal::getContainer());
    $dispatcher = new EventDispatcher();
    $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $response = new RedirectResponse('http://example.com/drupal');
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment