Clarify important note from module description

Created on 16 March 2023, about 2 years ago

Motivation

I arrived to the module description from the Weekly Drop newsletter and this module might be what I'm looking for. Decorates the module_handler like hux and uses events like hook_event_dispatcher.
Also might be the best candidate to transition core from hooks to events.

It is not clear to me what is meant by this phrase:

If the hook is invoked for the particular module (by ->invoke() method), the event won't be dispatched if the module has its hook implementation-defined.

Can you provide an example? Does it mean that the same module can't implement a hook an react to the same hook with an event listener?
Once is clear maybe I can help to make it better so is more obvious which are the limitations.

Proposed resolution

Remaining tasks

πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Documentation

Created by

πŸ‡ͺπŸ‡ΈSpain rodrigoaguilera Barcelona

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

Comments & Activities

  • Issue created by @rodrigoaguilera
  • Status changed to Needs review about 2 years ago
  • πŸ‡΅πŸ‡±Poland sayco ToruΕ„

    Hi @rodrigoaguilera! Thanks for such a write-up and so many kind words on this particular module.
    The thing about `invoke` in Drupal core is also a bit strange to me.
    The Drupal\Core\Extension\ModuleHandlerInterface the invoke "Invokes a hook in a particular module" in contrary to the `invokeAll` which "Invokes a hook in all enabled modules that implement it."

    From what I can see in the core, it is used mainly for the hooks like `install`, `uninstall`, `schema`, `mail`, `help`.

    I've decied that in case of the `invoke` which is called per module there is no point to dispatch the event for a specific module as well if it already has this hook implemented to avoid redundancy.
    I don't think this limitation do any harm, but if there will be a need for chaning this behaviour we can of course consider to change it.

    I hope my answer will somehow help you when working with the module.

    If you consider my answer as complete, please mark the issue as fixed, thanks!

  • πŸ‡ͺπŸ‡ΈSpain rodrigoaguilera Barcelona

    I get it now. I think is better to rephrase a bit.

    There is special hooks that are called only for a specific module, for example `install`, `uninstall`, `schema`, `mail` and `help` (by the invoke() method in the ModuleHandler). When the module "invoked" already has an implementation no event will be dispatched to avoid conflicts.

    I think the key there is to mention examples for the hooks. A developer that understands a hook_install will understand better the reason for that behavior.

    Also there is a typo in the module description: HookPreprocesEvent is missing an "s".

    I will give a try to hook_install ASAP.

Production build 0.71.5 2024