3 namespace Drupal\Core\Plugin\Discovery;
5 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
6 use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
10 * Provides a hook-based plugin discovery class.
12 class HookDiscovery implements DiscoveryInterface {
17 * The name of the hook that will be implemented by this discovery instance.
24 * The module handler used to find and execute the plugin hook.
26 * @var \Drupal\Core\Extension\ModuleHandlerInterface
28 protected $moduleHandler;
31 * Constructs a Drupal\Core\Plugin\Discovery\HookDiscovery object.
33 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
36 * The Drupal hook that a module can implement in order to interface to
37 * this discovery class.
39 public function __construct(ModuleHandlerInterface $module_handler, $hook) {
40 $this->moduleHandler = $module_handler;
47 public function getDefinitions() {
49 foreach ($this->moduleHandler->getImplementations($this->hook) as $module) {
50 $result = $this->moduleHandler->invoke($module, $this->hook);
51 foreach ($result as $plugin_id => $definition) {
52 $definition['provider'] = $module;
53 $definitions[$plugin_id] = $definition;