Problem/Motivation
Pretty much all of the other issues that are asking for OO hook implementations all run into the same problem: we have an unsettlingly large number of places throughout core that build a function name and then call it with some arguments, rather than calling ModuleHandler->invoke() or ModuleHandler->invokeAll().
This actively prevents implementation of a contrib module that, as an example, extends ModuleHandler and emits events when hooks are invoked. Pretty much anywhere where ModuleHandlerInterface->getImplementations() is used outside of ModuleHandler, there's likely a function name being constructed, and in the vast majority of these cases, it's unnecessary.
Proposed resolution
- Introduce two new hook invocation methods that take an additional callable (often, but not limited to, closures) that takes care of calling each individual hook implementation. Code currently calling
ModuleHandlerInterface::getImplementations()
to invoke hooks themselves can use custom callables to customize their hook invocations. This is useful to pass on extra parameters or process return values. - Mark
ModuleHandlerInterface::getImplementations()
deprecated, to encourage developers to use the (new)::invoke*()
methods instead.
Remaining tasks
Convert all remaining calls to ModuleHandlerInterface::getImplementations()
that do not cause test failures. If that's because of a lack of coverage, decide what to do about that.
Review, evaluate DX.
User interface changes
None.
API changes
None. Existing APIs are merely extended. ModuleHandlerInterface
is extended, which is not considered a break (@catch in #29)
Invoking modules must now replace their code which builds functions with calls to Module Handler. The call simply includes the hook name, and a closure which in turn calls the original hook via a closure. Modules that originally dealt with the return values of the invoked hooks, or relied on mutation of hook arguments, should pass along state via a use definition in the Module Handler closure.
Data model changes
None.