Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Plugin / Discovery / InfoHookDecorator.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
8 /**
9  * Allows info hook implementations to enhance discovered plugin definitions.
10  */
11 class InfoHookDecorator implements DiscoveryInterface {
12
13   use DiscoveryTrait;
14
15   /**
16    * The Discovery object being decorated.
17    *
18    * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
19    */
20   protected $decorated;
21
22   /**
23    * The name of the info hook that will be implemented by this discovery instance.
24    *
25    * @var string
26    */
27   protected $hook;
28
29   /**
30    * Constructs a InfoHookDecorator object.
31    *
32    * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
33    *   The object implementing DiscoveryInterface that is being decorated.
34    * @param string $hook
35    *   The name of the info hook to be invoked by this discovery instance.
36    */
37   public function __construct(DiscoveryInterface $decorated, $hook) {
38     $this->decorated = $decorated;
39     $this->hook = $hook;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getDefinitions() {
46     $definitions = $this->decorated->getDefinitions();
47     foreach (\Drupal::moduleHandler()->getImplementations($this->hook) as $module) {
48       $function = $module . '_' . $this->hook;
49       $function($definitions);
50     }
51     return $definitions;
52   }
53
54   /**
55    * Passes through all unknown calls onto the decorated object.
56    */
57   public function __call($method, $args) {
58     return call_user_func_array([$this->decorated, $method], $args);
59   }
60
61 }