Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Plugin / Discovery / ContainerDerivativeDiscoveryDecorator.php
1 <?php
2
3 namespace Drupal\Core\Plugin\Discovery;
4
5 use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator;
6
7 /**
8  * Injects dependencies into derivers if they use ContainerDeriverInterface.
9  *
10  * @see \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface
11  */
12 class ContainerDerivativeDiscoveryDecorator extends DerivativeDiscoveryDecorator {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function getDeriver($base_plugin_id, $base_definition) {
18     if (!isset($this->derivers[$base_plugin_id])) {
19       $this->derivers[$base_plugin_id] = FALSE;
20       $class = $this->getDeriverClass($base_definition);
21       if ($class) {
22         // If the deriver provides a factory method, pass the container to it.
23         if (is_subclass_of($class, '\Drupal\Core\Plugin\Discovery\ContainerDeriverInterface')) {
24           /** @var \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface $class */
25           $this->derivers[$base_plugin_id] = $class::create(\Drupal::getContainer(), $base_plugin_id);
26         }
27         else {
28           $this->derivers[$base_plugin_id] = new $class($base_plugin_id);
29         }
30       }
31     }
32     return $this->derivers[$base_plugin_id] ?: NULL;
33   }
34
35 }