Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / migrate / src / Plugin / Derivative / MigrateEntityRevision.php
1 <?php
2
3 namespace Drupal\migrate\Plugin\Derivative;
4
5 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7
8 class MigrateEntityRevision implements ContainerDeriverInterface {
9
10   /**
11    * List of derivative definitions.
12    *
13    * @var array
14    */
15   protected $derivatives = [];
16
17   /**
18    * The entity definitions
19    *
20    * @var \Drupal\Core\Entity\EntityTypeInterface[]
21    */
22   protected $entityDefinitions;
23
24   /**
25    * Constructs a MigrateEntity object.
26    *
27    * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_definitions
28    *   A list of entity definition objects.
29    */
30   public function __construct(array $entity_definitions) {
31     $this->entityDefinitions = $entity_definitions;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container, $base_plugin_id) {
38     return new static(
39       $container->get('entity.manager')->getDefinitions()
40     );
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
47     if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
48       return $this->derivatives[$derivative_id];
49     }
50     $this->getDerivativeDefinitions($base_plugin_definition);
51     return $this->derivatives[$derivative_id];
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function getDerivativeDefinitions($base_plugin_definition) {
58     foreach ($this->entityDefinitions as $entity_type => $entity_info) {
59       if ($entity_info->getKey('revision')) {
60         $this->derivatives[$entity_type] = [
61           'id' => "entity_revision:$entity_type",
62           'class' => 'Drupal\migrate\Plugin\migrate\destination\EntityRevision',
63           'requirements_met' => 1,
64           'provider' => $entity_info->getProvider(),
65         ];
66       }
67     }
68     return $this->derivatives;
69   }
70
71 }