0c49d048cd6d3b48c8274a781bfd52d835f70363
[yaffs-website] / web / core / modules / migrate_drupal / src / Plugin / migrate / source / EmptySource.php
1 <?php
2
3 namespace Drupal\migrate_drupal\Plugin\migrate\source;
4
5 use Drupal\Component\Plugin\DependentPluginInterface;
6 use Drupal\Core\Entity\DependencyTrait;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate\Plugin\migrate\source\EmptySource as BaseEmptySource;
10 use Drupal\Core\Entity\EntityManagerInterface;
11 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
12
13 /**
14  * Source returning an empty row with Drupal specific config dependencies.
15  *
16  * @MigrateSource(
17  *   id = "md_empty",
18  *   source_module = "system",
19  * )
20  */
21 class EmptySource extends BaseEmptySource implements ContainerFactoryPluginInterface, DependentPluginInterface {
22
23   use DependencyTrait;
24
25   /**
26    * The entity manager.
27    *
28    * @var \Drupal\Core\Entity\EntityManagerInterface
29    */
30   protected $entityManager;
31
32   /**
33    * {@inheritdoc}
34    */
35   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) {
36     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
37     $this->entityManager = $entity_manager;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
44     return new static(
45       $configuration,
46       $plugin_id,
47       $plugin_definition,
48       $migration,
49       $container->get('entity.manager')
50     );
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function calculateDependencies() {
57     // The empty source plugin supports the entity_type constant.
58     if (isset($this->configuration['constants']['entity_type'])) {
59       $this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
60     }
61     return $this->dependencies;
62   }
63
64 }