Allow any service to subscribe to hooks

Created on 27 January 2025, about 1 month ago

Problem/Motivation

We have a lovely new hooks system that integrates the module handler and the event dispatcher to invoke hooks. In doing this we had to move a hook. core_field_views_data to \Drupal\views\Hook\ViewsViewsHooks::fieldViewsData() even though what it does - provide entity reference field integration with views could be considered to be core's responsibility.

Also we've always had an issue with things that are not Drupal module's subscribing to events - for example PHP libraries. Another example could be kernel tests to enable hook testing whether the test and the test hook implementation live side-by-side - see πŸ“Œ Make hook testing with kernel tests very simple Active

Also this could be used to make things like

  /**
   * Implements hook_cron().
   */
  #[Hook('cron')]
  public function cron(): void {
    $this->workspaceManager->purgeDeletedWorkspacesBatch();
  }

from \Drupal\workspaces\Hook\WorkspacesHooks simpler. \Drupal\workspaces\WorkspaceManager::purgeDeletedWorkspacesBatch could subscribe to the hook - although we'd have to ensure anything that decorates it is also subscribed...

Proposed resolution

Allow services in some way to subscribe to hooks just like they can to other events.

Remaining tasks

User interface changes

None

Introduced terminology

None

API changes

TBD

Data model changes

None

Release notes snippet

TBD

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

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

Comments & Activities

Production build 0.71.5 2024