Updated: Comment #0
Problem/Motivation
We're going OO but we still have to keep procedural code because hooks can only be implemented by functions.
So what if we could also implement functions in services?
Well auto-magic discovery won't work because of naming conventions so we need a way to nominate what methods implement what hooks, enter module.implements.yml
Proposed resolution
Add a module.implements.yml that allows modules to nominate a service and a method that implements a hook.
Example:
hooks:
node_predelete: 'book.module:nodePreDelete'
Remaining tasks
More test coverage
Caching of parsed implementations - I think CachedModuleHandler handles this already but best confirm
What happens for those rough edges in core where we call foreach ($module_handler->implements($foo, $bar)) instead of using invokeAll?
Check that ModuleHandler::implements work too.
Data returned from ModuleHandler::getImplementations is no good, as it only returns the keys we need it to return the same as ::getImplementationInfo.
User interface changes
None
API changes
Well ModuleHandler::implements() && function_exists($module . '_' . $hook)
is no longer enough because we're also storing data in the implementations, not just the group. In these cases the data returned from ModuleHandler::getImplementations is no good, as it only returns the keys.
Related Issues
Attachment | Size | Status | Test result | Operations |
---|---|---|---|---|
services-implement-hooks.patch | 9.01 KB | Ignored | None | None |