Version 1
[yaffs-website] / web / core / modules / migrate / src / Plugin / NoSourcePluginDecorator.php
1 <?php
2
3 namespace Drupal\migrate\Plugin;
4
5 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
6 use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
7
8 /**
9  * Remove definitions which refer to a non-existing source plugin.
10  */
11 class NoSourcePluginDecorator 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    * Constructs a NoSourcePluginDecorator object.
24    *
25    * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
26    *   The object implementing DiscoveryInterface that is being decorated.
27    */
28   public function __construct(DiscoveryInterface $decorated) {
29     $this->decorated = $decorated;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getDefinitions() {
36     /** @var \Drupal\Component\Plugin\PluginManagerInterface $source_plugin_manager */
37     $source_plugin_manager = \Drupal::service('plugin.manager.migrate.source');
38     return array_filter($this->decorated->getDefinitions(), function (array $definition) use ($source_plugin_manager) {
39       return $source_plugin_manager->hasDefinition($definition['source']['plugin']);
40     });
41   }
42
43   /**
44    * Passes through all unknown calls onto the decorated object.
45    *
46    * @param string $method
47    *   The method to call on the decorated object.
48    * @param array $args
49    *   Call arguments.
50    *
51    * @return mixed
52    *   The return value from the method on the decorated object.
53    */
54   public function __call($method, array $args) {
55     return call_user_func_array([$this->decorated, $method], $args);
56   }
57
58 }