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
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 3259445-16.reduced-deprecation-totals.patch | 1.24 KB | jonathan1055 |
| #12 | 3259445-12-events.patch | 5.51 KB | tr |
Comments
Comment #2
tr commentedAssigning 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.
Comment #3
tr commentedThe 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.
Comment #4
tr commentedIn Drupal 8 we use and support two Event classes:
In Drupal 9, because we use a different version of Symfony, we need to support two more Event classes, for a total of four:
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:
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.
Comment #5
tr commentedComment #6
tr commentedComment #7
tr commentedThe 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.
Comment #9
tr commentedLet'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.
Comment #10
tr commentedAnd again with coding standards.
I feel like we can commit this one if nothing further shows up...
Comment #11
tr commentedWell, fixing those errors exposed some new errors. Here's a new patch.
Comment #12
tr commentedComment #14
tr commentedCommitted #12.
Comment #15
jonathan1055 commentedGood work. I will check the deprecations and adjust the Travis build file accordingly.
Comment #16
jonathan1055 commentedYes, 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 prefixwhich 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 librarywhich is on #3257978: The "core/jquery.ui" asset library is deprecated in drupal:9.2Comment #18
tr commentedCommitted #16. Thanks.