Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291765

Allow services to implement hooks by nominating methods in a module.implements.yml

$
0
0

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.

#1972304: Add a HookEvent

AttachmentSizeStatusTest resultOperations
services-implement-hooks.patch9.01 KBIgnoredNoneNone

Viewing all articles
Browse latest Browse all 291765

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>