Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Rewriter / GenericDeriver.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter;
4
5 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7
8 /**
9  * Builds derivative definitions for the generic rewriter, based on the
10  * drupalmoduleupgrader.rewriters configuration object.
11  */
12 class GenericDeriver implements ContainerDeriverInterface {
13
14   /**
15    * @var array
16    */
17   protected $config;
18
19   public function __construct(array $config) {
20     $this->config = $config;
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public static function create(ContainerInterface $container, $base_plugin_id) {
27     return new static(
28       $container->get('config.factory')->get('drupalmoduleupgrader.rewriters')->get('definitions')
29     );
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getDerivativeDefinition($derivative_id, $base_definition) {
36     $derivatives = $this->getDerivativeDefinitions($base_definition);
37
38     if (isset($derivatives[$derivative_id])) {
39       return $derivatives[$derivative_id];
40     }
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getDerivativeDefinitions($base_definition) {
47     $derivatives = [];
48
49     foreach ($this->config as $data_type => $definition) {
50       $derivatives[$data_type] = $definition + $base_definition;
51     }
52
53     return $derivatives;
54   }
55
56 }