Problem/Motivation

In #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter we introduced attributes and order classes to reorder hook implementations.
New OOP hook implementations are targeted with [$class, $method].
Procedural implementations are targeted with [ProceduralCall::class, $function], which is awkward.

The ProceduralCall class should rather be seen as something internal, which we had to introduce to work properly with event dispatcher. We might even remove it in #3506930: Separate hooks from events or a follow-up issue.

We must be able to target procedural hooks without using the ProceduralCall class name.

Steps to reproduce

Proposed resolution

Either allow to pass (just) a function name to the respective attributes and order classes.
OR have dedicated attributes and classes.

Internally, for now, we can convert these to insert ProceduralHook::class.
That class can be marked as internal (EDIT: This is already the case).

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3516146

Command icon 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

nicxvan created an issue. See original summary.

nicxvan’s picture

Title: [pp-1] Create new attribute to make reordering procedural hooks easier. » Create new attribute to make reordering procedural hooks easier.
Parent issue: #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter »
Related issues: +#3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter

I have been thinking about this since I created this and I'm really not sure we should do this.

donquixote’s picture

For now we need to target procedural hooks by setting ProceduralCall as the class name, which is awkward.
With #3506930: Separate hooks from events, which includes #3522211: Drop/replace the ProceduralCall class for hooks, we drop the class ProceduralCall.

We then either need #[ReOrderHook(function: ...)], or we need a separate attribute #[ReOrderProceduralHook($function)] or #[ReOrderHookFunction($function)]. Or we could pass $module instead of $function.

The main argument for a separate attribute would be to keep the other arguments required in the regular #[ReOrderHook] attribute.

In the same way we would need OrderBefore(function: ...) or OrderBeforeProcedural($module)

donquixote’s picture

Title: Create new attribute to make reordering procedural hooks easier. » Rethink hook ordering attributes targeting procedural hooks

Choosing a more open-ended issue title

donquixote’s picture

Issue summary: View changes
donquixote’s picture

Title: Rethink hook ordering attributes targeting procedural hooks » Rethink hook ordering attributes targeting procedural hooks without "ProceduralCall" class reference
donquixote’s picture

Issue summary: View changes
donquixote’s picture

It was argued in slack that we don't need to target _only_ a procedural implementation with e.g. #[RemoveHook].
Instead, one could simply target all implementations of the module, because most modules will either be fully on OOP or fully on procedural hooks.

One reason I can think of to support removing only a procedural implementation is if a module wants to work with two major versions of another module.
In that case, it may want to remove the procedural implementation from version 1 of the other module, but also remove a specific OOP implementation (but not all) from version 2 of that other module.

---

It was also argued that we should not add more attribute classes like RemoveProceduralHook, but rather add parameters to existing ones.

The counter-argument here would be that changing the signature of an existing class can be a painful thing to do with regard to BC, especially if we support named arguments passing, and if we want to add or remove more parameters in the future.

Introducing new classes tailored to specific cases is a lot easier.
Also, this means that we can keep parameters required, and we don't need to explain which combination of parameters is allowed or not.

nicxvan’s picture

Component: base system » extension system

donquixote changed the visibility of the branch 3516146-rethink-procedural-hook-ordering to hidden.

donquixote’s picture

I created a preview MR.
No tests, and more attributes than we should keep in the end.
The goal is to look at the different options we have, and decide what we like best.

nicxvan’s picture

We can likely close this when separate hooks from event dispatcher lands.

donquixote’s picture

The ProceduralCall class still feels alien to me.

nicxvan’s picture

Status: Postponed » Postponed (maintainer needs more info)

I know, I think this is a good compromise, it is now literally a stub just for remove and reorder.

I really think we need a stronger reason besides we don't like it.

This MR adds 4 attributes to remove one stub class and there is no clear idea how to release those change with bc.

How will contrib remove our reorder a hook and support 11.0, 11.1, 11.2 and whichever version this ends up in?

I really think this won't change, but I'll leave this open for a bit so we can discuss further.

nicxvan’s picture

I closed the other as a duplicate of this.

I still think we should clear this for the reasons in 15 but wasn't too leave it open for discussion.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

donquixote’s picture

I guess this kind of change would have needed to be done earlier, when we introduced the ordering attributes.

nicxvan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Yeah I agree.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.