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

Update the way modules implement hooks.

$
0
0

In Drupal 8's implementation of `module_implements`, every module is looped over and then function_exists is called to see if a module has implemented a specific hook. This works however there are probably better ways for modules to announce they are implementing a hook.

I propose using `Drupal\Core\Extension\ModuleHandler` (or another class) to register hooks. Something like the following might be a typical use case:

drupal_container()->get('module_handler')->registerHook(
  'menu',
  function(){
    return array(
      ..
    );
  }
);

I can see the following advantages:

  • More performant, no need to loop through every module and check if a function exists.
  • Doesn't fill global scope with unnecessary functions.
  • Clearly draws a line between what is a function and what is a hook.

I haven't looked too deeply into Drupal 8, so any feedback or comments would be welcomed.


Viewing all articles
Browse latest Browse all 299133

Latest Images

Trending Articles



Latest Images

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