How to find which Drupal module implements a given hook

With Drupal 7, you’d use the below Drush call:

$ drush ev "print_r(module_implements('menu'))"
Array
(
    [0] => block
    [1] => acquia_agent
    [2] => apachesolr
    [3] => apachesolr_search
    [4] => ckeditor
<snipped>
)

With Drupal 8, however, things have changed and have been documented under Module/hook system functions replaced with module_handler and module_installer service.

You can now leverage ModuleHandler::getImplementations($hook) like so:

With Psy Shell

>>> \Drupal::moduleHandler()->getImplementations('help');
=> [
     "automated_cron",
     "block",
     "block_content",
     "breakpoint",
     "ckeditor",
     "color",
(snipped)

With Drush php-eval

$ drush ev "print_r(\Drupal::moduleHandler()->getImplementations('help'))"
Array
(
    [0] => automated_cron
    [1] => block
    [2] => block_content
    [3] => breakpoint
    [4] => ckeditor
    [5] => color
(snipped)

Tags
Drupal

Date
September 14, 2016