Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Plugin / Discovery / HookDiscovery.php
1 <?php
2
3 namespace Drupal\Core\Plugin\Discovery;
4
5 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
6 use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8
9 /**
10  * Provides a hook-based plugin discovery class.
11  */
12 class HookDiscovery implements DiscoveryInterface {
13
14   use DiscoveryTrait;
15
16   /**
17    * The name of the hook that will be implemented by this discovery instance.
18    *
19    * @var string
20    */
21   protected $hook;
22
23   /**
24    * The module handler used to find and execute the plugin hook.
25    *
26    * @var \Drupal\Core\Extension\ModuleHandlerInterface
27    */
28   protected $moduleHandler;
29
30   /**
31    * Constructs a Drupal\Core\Plugin\Discovery\HookDiscovery object.
32    *
33    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
34    *   The module handler.
35    * @param string $hook
36    *   The Drupal hook that a module can implement in order to interface to
37    *   this discovery class.
38    */
39   public function __construct(ModuleHandlerInterface $module_handler, $hook) {
40     $this->moduleHandler = $module_handler;
41     $this->hook = $hook;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getDefinitions() {
48     $definitions = [];
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;
54       }
55     }
56     return $definitions;
57   }
58
59 }