94x: Symfony\Component\EventDispatcher\Event is deprecated in drupal:9.1.0 and will be replaced by Symfony\Contracts\EventDispatcher\Event in drupal:10.0.0. A new Drupal\Component\EventDispatcher\Event class is available to bridge the two versions of the class. See https://www.drupal.org/node/3159012

CR https://www.drupal.org/node/3159012

These deprecation messages were introduced following the changes in #3172039-17: [9.1] EventDispatcherInterface::dispatch() parameter argument order changed

Comments

jonathan1055 created an issue. See original summary.

tr’s picture

Assigned: Unassigned » tr

Assigning this to myself because I have already been working on this. See #3172039-20: [9.1] EventDispatcherInterface::dispatch() parameter argument order changed and #3257308: Symfony Event class deprecated. The latter is the fix I made in Rules Essentials to see if that change had any side effects for modules that integrate with Rules.

tr’s picture

Priority: Normal » Major

The Drupal core 10.0.x branch has now been updated to use Symfony 5.4, so Symfony\Component\EventDispatcher\Event is no longer available in Drupal 10 and our tests now fail with Drupal 10.

So it is now more important to get this fixed using the Drupal\Component\EventDispatcher\Event so that Rules will continue to work in both Drupal 9 and Drupal 10.

tr’s picture

Status: Active » Needs review
StatusFileSize
new2.26 KB

In Drupal 8 we use and support two Event classes:

  • Symfony\Component\EventDispatcher\Event
  • Symfony\Component\EventDispatcher\GenericEvent

In Drupal 9, because we use a different version of Symfony, we need to support two more Event classes, for a total of four:

  • Drupal\Component\EventDispatcher\Event (for BC - in D9 this extends Symfony\Component\EventDispatcher\Event)
  • Symfony\Component\EventDispatcher\Event (deprecated)
  • Symfony\Contracts\EventDispatcher\Event
  • Symfony\Component\EventDispatcher\GenericEvent

In Drupal 10, again because of a change in Symfony version, we now need to support only three Event classes, but these are different classes:

  • Drupal\Component\EventDispatcher\Event (for BC - in D10 this now extends Symfony\Contracts\EventDispatcher\Event)
  • Symfony\Contracts\EventDispatcher\Event
  • Symfony\Contracts\EventDispatcher\GenericEvent

The problem I'm having is that for our event subscribers, we no longer have a way to type hint all these events so that the code works in both D9 and D10. This is because there is no common base class / interface that will work for all events. The CR recommends dropping the type hint entirely, which I think is A Bad Idea.

The real problem is with the GenericEvent, which in D9 subclasses Symfony\Component\EventDispatcher\Event but in D10 subclasses Symfony\Contracts\EventDispatcher\Event. These are two incompatible types. While Drupal core provided a BC layer for the "normal" Event class, it did NOT do the same for the GenericEvent class, I guess because core doesn't use that class so didn't think it was important.

Regardless, Rules used to encourage use of GenericEvent, and all our EntityEvents subclass GenericEvent. I would rather not lose the ability to trigger on GenericEvents because I know there are some contrib modules that use this, so I don't see it as an option just to forbid these events or to change Rules core so that Rules doesn't use GenericEvents any more.

Here's a patch that gets rid of just a few of the deprecations. I don't think I can get rid of the rest without dropping the type hints.

tr’s picture

Component: Rules Core » Events
tr’s picture

The patch in #4 reduced the number of D10 fails from 21 to 8, so I think it's worthwhile to commit #4 now but leave this issue open so we can continue to address the remaining problems.

  • TR committed eb34e57 on 8.x-3.x
    Issue #3259445 by TR: Symfony\Component\EventDispatcher\Event is...
tr’s picture

StatusFileSize
new1.77 KB

Let's try this. In this patch I change one type hint to be 'object' instead of 'Event', and I add comments and a check to make sure we're really getting an Event object. I also add a @todo to restore this in D10.

tr’s picture

StatusFileSize
new1.94 KB

And again with coding standards.

I feel like we can commit this one if nothing further shows up...

tr’s picture

StatusFileSize
new4.77 KB

Well, fixing those errors exposed some new errors. Here's a new patch.

tr’s picture

StatusFileSize
new5.51 KB

  • TR committed 85af8d7 on 8.x-3.x
    Issue #3259445 by TR: Symfony\Component\EventDispatcher\Event is...
tr’s picture

Status: Needs review » Fixed

Committed #12.

jonathan1055’s picture

Good work. I will check the deprecations and adjust the Travis build file accordingly.

jonathan1055’s picture

Yes, this has removed the deprecation messages "EventDispatcherInterface::dispatch() with a string event name". Patch attached. Testing of this patch does not need to be run on drupal.org as it only changes the .travis.yml file.

At 9.1 we just have 50 of the single deprecation Support for keys without a placeholder prefix which is covered by
#3172046: [10] Fix automated test results - Support for keys without a placeholder prefix is deprecated (Rules)

At 9.2 we have the above plus a combined 646 for core/jquery.ui... asset library which is on #3257978: The "core/jquery.ui" asset library is deprecated in drupal:9.2

  • TR committed d11634f on 8.x-3.x authored by jonathan1055
    Issue #3259445 by jonathan1055: Update .travis.yml for Symfony\Component...
tr’s picture

Committed #16. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.