Problem/Motivation
Module authors converting their procedural code to services would like to implement hooks in said services without procedural code.
Proposed resolution
In ModuleHandler:
<?php
public function invokeAll($hook, $args = array()) {
$event = new HookEvent("hook.$hook", $args)
\Drupal::service('event_dispatcher')->dispatch($event);
$return = $event->getResults();
// ... the rest of the function is unchanged.
}
?>
this way people can write dependency injected services implementing a hook instead of procedural code. As we hope to attract new developers more accustomed to OOP, this is sort of important.
Remaining tasks
Update module handler as required
Create HookEvent
Convert remaining hook invocations that do not use ModuleHandler::invokeAll ie where module_implements is used instead. There are two kinds: one that wants to pass around references, these are easy to convert because invokeAll takes an array of arguments instead of a variable number of arguments and the array simply can contain the references. Those that want to record the module that returned certain information will need some consideration (permissions do this for uninstall). The problematic cases will likely be handled in a followup.
User interface changes
None
API changes
Module maintainers can implement hooks in their service classes.
ModuleHandler::moduleImplements likely becomes a protected method.