Closed (fixed)
Project:
Drupal core
Version:
9.2.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Jul 2020 at 17:12 UTC
Updated:
24 Feb 2021 at 09:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dww+1. Similar approach at #3157895: Move 'install_time' state update from \Drupal\Core\Installer\Form\SiteConfigureForm to installed_finished() which is what I was referring to in our Slack thread about this.
Even if the arguments aren't type hinted, the PHPDoc can say:
So long as the code comment to explain what's happening uses my "prevent cascade of WTF" formulation, I'm happy. 😉 The code would be approximately this:
More or less...
Cheers,
-Derek
Comment #3
catchComment #4
catchMade a start on this, feels very crufty though, possibly more crufty than having to commit the find and replace when we do the actual Symfony 5/6 update.
Comment #6
meenakshig commentedComment #7
sanjayk commentedPlease avoid assigning issues to your self as this is discourage for D.O contributors in general.
Kindly go though the given link for better understanding of do's and don't
https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...
Comment #9
gábor hojtsy@Meenakshi.g: assigning issues to yourself is fine if you are going to work on them in a short timeframe. See the linked docs.
Reviewing the current patch I don't have *strong* feelings whether this manual checking is better or not than swapping out the interface in Drupal 10. I am leaning towards just doing the replacements in Drupal 10 otherwise we need to mark these code paths somehow for removal in Drupal 10, at least they would not be applicable then (unless we want to keep a BC layer in Drupal 10, which I don't think we want).
Found these minor code style things:
The line break is not supposed to be here, is it? It is not in the other half of changes in the file.
Comment #10
Pooja Ganjage commentedHi,
Creating a patch as per the #9 comment suggestion.
Please review the patch.
Let me know if any suggestions.
Thanks.
Comment #11
longwaveI think the line breaks here and elsewhere are wrong too, at least PhpStorm doesn't understand the class name when it is broken over two lines.
Comment #12
Pooja Ganjage commentedUpdated patch as per the #11 comment suggestion.
Comment #13
Pooja Ganjage commentedComment #14
longwaveThe line breaks in @var are still not right. We are allowed to go over 80 characters here, it must be kept on a single line:
should be
Comment #15
longwaveI also wonder if instead of doing this dance we can add some kind of BC/FC layer with
class_alias()?Comment #16
longwaveSymfony\Component\EventDispatcher\EventDispatcherInterface looks like this:
ie. the new interface is the parent of the old interface. So can't we just widen the type in all these constructors now? Any caller that still passes a Component EventDispatcherInterface will satisfy Contracts EventDispatcherInterface.
As an example:
The first half of the check is redundant because EventDispatcherInterface is an instance of ContractsEventDispatcherInterface already. And so this can be reduced to:
But we don't even need this check - we can just use the parameter type?
Comment #17
longwaveStraight find and replace as per #16.
Comment #18
catchYes you're right. This has been the case since Symfony 4.3 and we require 4.4, so just doing the switch is fine.
Comment #19
daffie commentedComment #20
daffie commentedAll instances of
Symfony\Component\EventDispatcher\EventDispatcherInterfacehave been replaced bySymfony\Contracts\EventDispatcher\EventDispatcherInterface. I did a code base search.All code changes in the patch look good to me.
For me it is RTBC.
Should we also replace
Symfony\Component\EventDispatcher\EventwithSymfony\Contracts\EventDispatcher\Event? As the first is also deprecated since Symfony 4.3. See: https://github.com/symfony/event-dispatcher/blob/4.4/Event.phpComment #21
catch@daffie
I don't think we can for that - because code written for Drupal 8.9.x can be using the Component version (and can't update to the contracts version), and while that code will trigger a deprecation on Drupal 9, it needs to run until Drupal 10. The Component class doesn't inherit from the Contracts class. We added our own
Drupal\Component\EventDispatcher\Eventclass to bridge the two (so that 9.1.x+ code can extend that class and not have to change anything in 10.0.x where we can just change the use statement in the one class). I think having to do that for theEventclass is what threw me off when I opened this issue on the simpler solution in #17.Comment #22
daffie commented@catch: Thank you for your explanation!
Comment #24
catchSince this is just a straight find and replace now that makes it an easy commit.
Rather than ask for/create a new change record, I've added a note about this to https://www.drupal.org/node/3159012 - it's a Symfony-only change in terms of the API change itself, but worth documenting ourselves.
Committed a9cee68 and pushed to 9.2.x. Thanks!
Comment #25
mondrakeI think this has broken Drush, https://github.com/drush-ops/drush/issues/4614
Comment #26
catchI think we need to roll this hunk back.
Comment #28
catchReverted the commit for now. That change isn't a type hint, it's the interface the dispatcher implements, and we can't change that. Was over-excited seeing the simpler changes in the rest of the patch and didn't fully look at the consequences of that one. We need to allow code that's type hinting the old interface to continue to work throughout Drupal 9.
Comment #29
ravi.shankar commentedLooks like forgot to unassign.
Comment #30
jonathan1055 commentedThank you for the roll-back in #27 - yes this killed 75 of the tests in the Rules module at core 9.2. For information, the error was:
Those daily tests failed only on that one day, after the commit in #23. After the revert, they all run OK again. Is there any type of "simulated" contrib testing modules that are run as part of d.o. testing? It would seem that this fault should have been detectable?
Comment #31
daffie commentedTo fix this issue we need to keep the existing class:
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcherwhich implementsSymfony\Component\EventDispatcher\EventDispatcherInterfaceand the class:Drupal\Component\EventDispatcher\Eventwhich extends the classSymfony\Component\EventDispatcher\Event.The problem is that the class
Symfony\Component\EventDispatcher\Eventis deprecated and that we need to replace the interfaceSymfony\Component\EventDispatcher\EventDispatcherInterfacewith the interfaceSymfony\Contracts\EventDispatcher\EventDispatcherInterface. As we cannot create a BC break, we must keep the existing classes.Creating replacements for the two classes can be named in a number of ways:
Drupal\Component\EventDispatcher\ContractsContainerAwareEventDispatcherandDrupal\Component\EventDispatcher\ContractsEvent;Drupal\Component\ContractsEventDispatcher\ContainerAwareEventDispatcherandDrupal\Component\ContractsEventDispatcher\Event;Drupal\Contracts\EventDispatcher\ContainerAwareEventDispatcherandDrupal\Contracts\EventDispatcher\Event.My question which should we choose?
Comment #32
catchhmm my impression from the test failures was we only needed to remove the hunk mentioned in #26.
We'll still be using the deprecated class in that one place, but that's an easy 10.x-only change to make.
Comment #34
catchNeeded to remove the respective test hunk as well.
Comment #35
catchComment #36
daffie commented@catch: Thank you for working on this issue. When I look at your patch it only replaces
Symfony\Component\EventDispatcher\EventDispatcherInterfacewithSymfony\Contracts\EventDispatcher\EventDispatcherInterface. Unfortunately there needs to be done more in this issue. The classDrupal\Component\EventDispatcher\Eventextends the classSymfony\Component\EventDispatcher\Eventand that class is also deprecated. See: https://github.com/symfony/event-dispatcher/blob/4.4/Event.php.Comment #37
longwave@daffie That class was added to provide a forward-compatibility layer, downstream users of the Symfony Event class should now extend the Drupal class and then in Drupal 10 we can seamlessly switch the parent class from Symfony\Component to Symfony\Contracts.
See #3055198: [Symfony 5] Symfony/Component/EventDispatcher/Event is deprecated in Symfony 4.3 use Symfony/Contracts/EventDispatcher/Event instead for more info.
Comment #38
longwaveRerolled #35.
Comment #39
kristen polThanks for updating the patch.
1) Went through all changes and confirmed Component is changed to Contracts.
2) When looking for remaining instances of
Symfony\Component\EventDispatcher\EventDispatcherInterface, it's referenced below which isn't part of the issue summary:3) Patch applies to 9.2.
4) Tests pass.
5) One thing in the issue summary and noted in comment #2:
This isn't covered in the patch so either it should be removed from the issue summary or added to the patch or a follow-up issue should be created.
6) Another thing in the issue summary:
Does this issue need to be created as a follow-up issue so it's not forgotten?
Comment #40
catch@Kristen Pol
#39.2 -this is part of our bc layer for other changes in event dispatcher and will be removed when 10.0.x opens, so fine for that reference to stay.
#39.5 and #39.6 - the issue summary was out of date, this issue changed direction since it opened. Have updated.
Comment #41
kristen polThanks for updating the issue summary and providing clarification. Looks good to me based on last 2 comments so marking RTBC.
Comment #42
alexpottCommitted c4d6699 and pushed to 9.2.x. Thanks!