3 namespace Drupal\migrate\Plugin\Derivative;
5 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
8 class MigrateEntity implements ContainerDeriverInterface {
11 * List of derivative definitions.
15 protected $derivatives = [];
18 * The entity definitions
20 * @var \Drupal\Core\Entity\EntityTypeInterface[]
22 protected $entityDefinitions;
25 * Constructs a MigrateEntity object.
27 * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_definitions
28 * A list of entity definition objects.
30 public function __construct(array $entity_definitions) {
31 $this->entityDefinitions = $entity_definitions;
37 public static function create(ContainerInterface $container, $base_plugin_id) {
39 $container->get('entity.manager')->getDefinitions()
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];
50 $this->getDerivativeDefinitions($base_plugin_definition);
51 return $this->derivatives[$derivative_id];
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",
65 'requirements_met' => 1,
66 'provider' => $entity_info->getProvider(),
69 return $this->derivatives;