Verified Commit e5fbc651 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3319791 by Cyberwolf, Chi, longwave: ContainerAwareEventDispatcher...

Issue #3319791 by Cyberwolf, Chi, longwave: ContainerAwareEventDispatcher should not expect the dispatched event to be stopable

(cherry picked from commit 17fa1745)
parent ef4dc872
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Component\EventDispatcher;

use Psr\EventDispatcher\StoppableEventInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -95,6 +96,8 @@ public function dispatch(object $event, ?string $eventName = NULL): object {
        unset($this->unsorted[$event_name]);
      }

      $stoppable = $event instanceof StoppableEventInterface;

      // Invoke listeners and resolve callables if necessary.
      foreach ($this->listeners[$event_name] as &$definitions) {
        foreach ($definitions as &$definition) {
@@ -106,7 +109,7 @@ public function dispatch(object $event, ?string $eventName = NULL): object {
          }

          call_user_func($definition['callable'], $event, $event_name, $this);
          if ($event->isPropagationStopped()) {
          if ($stoppable && $event->isPropagationStopped()) {
            return $event;
          }
        }
+3 −1
Original line number Diff line number Diff line
@@ -312,6 +312,8 @@ public function testDispatch() {
    $this->assertFalse($this->listener->postFooInvoked);
    $this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(new Event(), 'noevent'));
    $this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(new Event(), self::PREFOO));
    // Any kind of object can be dispatched, not only instances of Event.
    $this->assertInstanceOf(\stdClass::class, $this->dispatcher->dispatch(new \stdClass(), self::PREFOO));
    $event = new Event();
    $return = $this->dispatcher->dispatch($event, self::PREFOO);
    $this->assertSame($event, $return);
@@ -566,7 +568,7 @@ class TestEventListener {
  /**
   * Listener methods.
   */
  public function preFoo(Event $e) {
  public function preFoo(object $e) {
    $this->preFooInvoked = TRUE;
  }