Let the hook cache store arbitrary callbacks instead of module names

Created on 8 July 2014, over 10 years ago
Updated 30 January 2023, almost 2 years ago

Currently the hook cache is an array of the format $module_name => $group.

We also know that the hook system is fragile.
sun suggested to allow an alternative format with Drupal\$module\Hook::foo() (and other proposals existed before that):
🌱 Allow module services to specify hooks Needs work

As a preparational step before any such move, I suggest to change the hook cache so that it can be filled with arbitrary callbacks.
For the start, these can be added with hook_module_implements_alter().

Later we can add patterns like Drupal\$module\Hook::foo() or Drupal\$module\hook_foo(). This could even happen post-release, since it would only extend the API and not break it. (unless a module already defines a class that matches the pattern.. duh)

The change of the hook cache brings only one API break: It changes the structure of hook_module_implements_alter().
hook_hook_info() will continue to work as it does today.

Challenge: We still need a way to store which files should be included for a hook implementation. We may want to store the module name and the file path relative to the module dir. This way, things don't break if modules are moved around.
This means the simple array structure of $module_name => $group no longer does the job.

Note: #2263365: Second loop in module_implements() being repeated for no reason. β†’ should be fixed first!

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡©πŸ‡ͺGermany donquixote

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024