Move hook_implementations_map generation to late in service container compilation to make altering hooks classes more DX friendly

Created on 24 May 2025, 10 days ago

Problem/Motivation

The way hook_implementations_map is created alongside adding kernel.event_listener tags makes it difficult for other compiler passes to conditionally undefine hook classes with their own criteria. If you want to undefine the hooks class, you must also update the hook_implementations_map parameter at the same time. And doing so requires either either: hardcoding the unsets for each method, use reflection to find the hooks to undefine, or loop through all implementations which is very non-performant.

See also thread at https://git.drupalcode.org/project/drupal/-/merge_requests/12156#note_51... . A code comment has been added to that MR, referencing this issue.

Proposed resolution

hook_implementations_map should be deferred to very late in the process since it is just a memoization of what was discovered, at least with a very late weight/priority in the current compiler pass order. Or perhaps use a differnt compiler pass later than the existing\Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION. See \Symfony\Component\DependencyInjection\ContainerBuilder::addCompilerPass. This call currently happens in \Drupal\Core\CoreServiceProvider::register.

We should give the parameter a different name, like prefixed with a `dot`, to signify it is internal. Combined with a [class] constant of some kind to keep things referential.

I Imagine this kind of internal parameter doesn't have BC.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024