Mercurial > hg > isophonics-drupal-site
comparison core/modules/migrate/src/Plugin/Derivative/MigrateEntity.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 MigrateEntity 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 $class = is_subclass_of($entity_info->getClass(), 'Drupal\Core\Config\Entity\ConfigEntityInterface') ? | |
60 'Drupal\migrate\Plugin\migrate\destination\EntityConfigBase' : | |
61 'Drupal\migrate\Plugin\migrate\destination\EntityContentBase'; | |
62 $this->derivatives[$entity_type] = [ | |
63 'id' => "entity:$entity_type", | |
64 'class' => $class, | |
65 'requirements_met' => 1, | |
66 'provider' => $entity_info->getProvider(), | |
67 ]; | |
68 } | |
69 return $this->derivatives; | |
70 } | |
71 | |
72 } |