Problem/Motivation
We need to add stubs for the order parameter and objects for: #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter
Long discussion in slack: https://drupal.slack.com/archives/C079NQPQUEN/p1741870906383859
Basically since the order parameter and associated objects will not exist and will create a fatal error. We can add the order parameter earlier and stubs for the objects. This will prevent fatal errors.
Steps to reproduce
N/A
Proposed resolution
Add new Hook signature
Add Attributes and Order objects
Update docs to mention 11.2 +
Remaining tasks
N/A
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3512835-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-3512835
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nicxvan commentedComment #3
nicxvan commentedComment #4
catchThis seems critical for 11.1.x and very nice to have for 11.0.x and lower.
Comment #5
nicxvan commentedComment #10
nicxvan commentedComment #11
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #12
nicxvan commentedI think the bot is trying to merge with HEAD
Comment #13
smustgrave commentedAppears to have pipeline issues
Comment #14
nicxvan commentedGitlab is not picking up my change, I fixed this 5 hours ago, and now I cannot apply a suggestion to it.
Comment #15
smustgrave commentedI tried too and got a “file has been changed”
Wonder if 11.1x branch permission?
Comment #16
nicxvan commentedNew commit worked.
Comment #17
smustgrave commentedMoving to NW because all the tests appear to be failing
Comment #18
dwwPHP Fatal error: Uncaught Error: Call to undefined method Drupal\Core\Hook\Attribute\Hook::setMethod() in /builds/issue/drupal-3512835/core/lib/Drupal/Core/Hook/HookCollectorPass.php:289
Comment #19
nicxvan commentedYeah I forgot a method, I'll move it in later tonight.
Comment #20
nicxvan commentedComment #21
smustgrave commentedAll seems good now.
Comment #25
larowlanCommitted to 11.1.x and backported to 10.5.x and 11.0.x
Comment #27
larowlanComment #28
donquixote commentedDid the PREFIX and SUFFIX need backporting?
Comment #30
larowlanThe 10.5.x backport failed - we're using readonly properties here which aren't allowed on the versions of PHP 10.x supports
Comment #31
nicxvan commentedI can roll a 10.5 specific if someone doesn't before me.
Comment #32
nicxvan commentedComment #33
nicxvan commentedCreated #3523163: [10.5.x] Add BC stubs for Hook ordering. because creating 10.5 from here was too out of date.
Comment #34
nicxvan commentedComment #35
donquixote commentedThis MR did a lot more than what we need to for the BC support.
We absolutely don't need all these new attributes.
We only need to make the existing attributes compatible with new modules.
We did have a very clear plan for this, which we somehow forgot.
Missing attributes are ok, because we call ->getAttributes() with a type parameter. Only attributes classes with incompatible constructor signature are a problem.
We should either revert this and do again, or remove all the changes we don't need.
And before the next release for 11.1.x or 11.0.x. (if that has not already happened, I am not following).
Comment #36
nicxvan commentedI'm not sure what plan you are referring to, we backported Hook and LegacyHook to 10.4 as part of the original OOP hook initiative so we followed the same here.
In this case the Order classes are required otherwise there would be a fatal, and since we backported Hook already we need to backport those as well to all branches.
None of the plumbing for collection or ordering was backported, why are you concerned about backporting these classes, what could it possibly affect, they are not used.
Comment #37
donquixote commented(recap of what I said in slack)
My concern is this:
We have a grace period before 11.2.0 to tweak api details of the new attributes and API features we are adding.
But whatever we put into older versions of Drupal may get released before 11.2.0, as part of a minor release. At that point we can no longer change these, so we are cutting that grace period short.
Also for disruptive future changes to the new attributes, we now will need to cater to the 10.5.x, 11.0.x and 11.1.x as well.
Worse, we could have contrib modules written for 11.2.x that are compatible with 10.5.x but not with 10.6.x, or vice versa, because we just backported another change.
You are correct about order classes though, we do need these in any branch that collects hook attributes.
(more below)
I remember a discussion where we determined that missing attributes are not a problem, only incompatible constructors.
The conclusion was that we update existing attributes in older versions where they exist, to allow alternative parameters, but that we don't backport all new attribute classes.
For concerns with phpstan, I am sure this can be handled in some way.
I would have complained about backporting hook attribute to 10.x, but I probably did not pay attention at the time.
This is correct, we do have to backport the order classes to any branch which has the Hook attribute class, OR any branch where we actually collect hook attributes.
But this also means: If we had not backported the Hook class to 10.x, we now would not have to create BC stubs for 10.x.
The attribute classes are part of public API, the plumbing is not.
In general, releasing public API features is easy, the problem is that we cannot easily remove or change them later.
Comment #38
donquixote commentedFollow-up here: #3523385: [11.1] Reduce hook attribute order BC stubs to the minimum necessary
Comment #39
donquixote commented