Problem/Motivation

Core now has most of its hook invocations centralized to ModuleHandler, which allows this project to move invocations to a decorated dispatcher service rather than dispatching procedurally via .module files.

This is a partial proof of concept implementation which shows how the project can utilise these enhancements to core.

This will require that minimum Drupal version is 9.4. I suggest creating a new major or minor Drupal version of this project in order to responsibly go forward.

Invocations are moved from .module files to a ModuleHandler decorator, which offloads event creation to tag based factories. Ultimately most or all module files can be removed

Because of the scale of the changes required to satisfy this issue I've only gone ahead and implemented a small part of the project as an example. In case this is rejected. Also you may want to open separate issues to do address individual submodules work:

  • Core submodule, partially implemented
  • Field submodule, partially implemented
  • User submodule, fully implemented
  • Other submodules, fully implemented

With this work you can see multiple events can be dispatched per hook, events can be constructed in a special manner, events with return values are returned to the invoker, and alter arguments are passed by reference.

I personally don't use in this project, especially as I maintain Hux which is a good alternative to this project. During development of my contributions to the core issue useful to Hux, I identified that both of our projects could benefit.

The idea is the behaviour (input/output) does not change. There is only internal code optimizations and cleanups.

Remaining tasks

  • Review viability
  • Work out a plan for which version this should be implemented in
  • Migrate remaining hook implementations from .module files to Factory services.
    • core_event_dispatcher_theme
    • field_event_dispatcher_field_formatter_settings_summary_alter
    • field_event_dispatcher_field_formatter_third_party_settings_form
    • field_event_dispatcher_field_widget_settings_summary_alter
    • field_event_dispatcher_field_widget_third_party_settings_form

User interface changes

API changes

New event factories
Internal tagged services
ModuleHandler decorator
Interface for event return values.
Interface + base for self event factory

Data model changes

Order of event invocation may change.

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

dpi created an issue. See original summary.

dpi’s picture

Version: 4.x-dev » 3.x-dev
Assigned: dpi » Unassigned

Doesn't look like tests are enabled for 4.x

dpi’s picture

el7cosmos’s picture

Version: 3.x-dev » 4.x-dev

Loves the idea. We can continue this effort.

Test for 4.x branch now enabled.

el7cosmos’s picture

I'm thinking to implement this in 3.x and keep support for core < 9.4

dpi’s picture

Note there are some hooks that wont work with this code until Drupal 9.4.

See the list at the bottom of https://www.drupal.org/node/3000490

Until then you will need to keep the old hooks in .module.

el7cosmos’s picture

Version: 4.x-dev » 3.0.1

Yes, old hooks will still be maintained in .module file, check for core version and tag with deprecation, I'll try to push to another branch

el7cosmos’s picture

Version: 3.0.1 » 3.2.0

Tests are passed against 9.3 and 9.4. We still need to fix phpcs, phpstan, and phpmd violations.

dpi’s picture

For the PHPStan errors above.

The constructors for most of the events in this project could probably be made final, as they are considered internal/private.

public function __construct( -> final public function __construct(

-

Much of the docs included here has a bunch of new PHPStan data types. I'd suggest ignoring Drupal.Commenting.FunctionComment.IncorrectParamVarNam and Drupal.Commenting.FunctionComment.InvalidReturn. But only ignore them if you plan to use PHPStan, as Stan provides the safety for you here.

el7cosmos’s picture

I introduce a plugin system instead to discover event classes.

el7cosmos’s picture

Issue summary: View changes
el7cosmos’s picture

Issue summary: View changes

  • el7cosmos committed b71e625 on 3.x
    Issue #3277301 by el7cosmos, dpi: Adapt to centralised hook dispatcher...
el7cosmos’s picture

Status: Active » Fixed

Thanks @dpi

  • el7cosmos committed 9b46abd on 4.x
    Issue #3277301 by el7cosmos, dpi: Adapt to centralised hook dispatcher...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dpi’s picture

singularo’s picture