Hooks

Categories

Component ID

2510706

Component name

Hooks

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

340

Component created

Component changed

Component body

This modules allows you to implement Drupal hooks with object-orientated classes, this has a number of benefits:

  1. Your hooks live in classes, much more inline with Drupal 8
  2. Your hooks can use dependency injection, great for testing etc.
  3. You can use a class to organise your code rather than having monster size hooks or global functions that are only used as hook helpers.
  4. The overhead of running this module is nearly zero on normal pages, it will add a few hundred milliseconds to a cache clear though.

Currently this module only supports alter hooks although i'm discussing approaches to support invoke() and invokeAll() - https://www.drupal.org/node/2595769

Do not use this module in production yet, the architecture is not finalised.

Current Usage

Events - Create an event subscribe called "hooks.$your_hook_name" , you will receive an instance of HookEvent.
Implicit - Currently commented out in our ModulerHandler override, allows you to simply put the class in the right location to work. Likely to be removed in #2611020: Remove implicit style hooks