Decide between events and OOP hooks

Created on 2 February 2025, 3 days ago

In #3023704: Convert hooks to events β†’ we deprecated all hooks and created events as replacements, to be in line with modern PHP practices. Back then I think we also assumed that sooner or later most of Drupal code would follow in that direction.

However, now that Drupal support OOP hooks (see πŸ“Œ OOP hooks using event dispatcher Needs review and its change record β†’ ) it seems Core has decided against embracing events after all in favor of a modernized version of the existing β€œhook” Drupalism.

Now the question is what we want to do in this module: Do we want to keep moving towards events and remove all of our hooks, as announced, in version 2.0.0 of the module? Or do we reverse course, deprecate the events instead and keep using the hooks (while converting our implementations to OOP)?

It seems OOP hooks have largely the same advantages as events now, so the question is probably whether we want to be more in line with what Drupal does or with that every other PHP project does? (With perhaps the added thought that we already moved from hooks to events, so moving back might be a bit annoying to anyone who already converted their hook implementations.)

Other arguments and opinions would be very welcome!

🌱 Plan
Status

Active

Version

1.0

Component

Framework

Created by

πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @drunken monkey
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    With perhaps the added thought that we already moved from hooks to events, so moving back might be a bit annoying to anyone who already converted their hook implementations.

    I think this is a big argument to keep moving ahead in the direction we already established.

  • Unless there is a particular advantage or disadvantage to using events over OOP hooks I'd stick with what is there for a bit and see how the community shakes out (both other php projects and drupal itself). It seems like there's some waffling going on.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    I think we should stick with events.

  • heddn Nicaragua

    Events are fine. Hooks are fine for what they are, but events seem less hacky.

  • πŸ‡©πŸ‡°Denmark xen

    Well, let me submit the opposing viewpoint then: I think search_api should use OO hooks. Reasoning, in no particular order:

    * Drupal Core has decided this is how we do things in Drupal land.

    * search_api is a prominent project, and its codebase is read by many an aspiring developer, I think it ought to show the proper path.

    * The ergonomics of OO hooks is, IMO, better.

    * OO hooks is AFAIK based on events anyway.

Production build 0.71.5 2024