e0acc4b52e30b8a8cf226e52909c282755250bf6
[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  * )
19  */
20 class EmptySource extends BaseEmptySource implements ContainerFactoryPluginInterface, DependentPluginInterface {
21
22   use DependencyTrait;
23
24   /**
25    * The entity manager.
26    *
27    * @var \Drupal\Core\Entity\EntityManagerInterface
28    */
29   protected $entityManager;
30
31   /**
32    * {@inheritdoc}
33    */
34   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) {
35     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
36     $this->entityManager = $entity_manager;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
43     return new static(
44       $configuration,
45       $plugin_id,
46       $plugin_definition,
47       $migration,
48       $container->get('entity.manager')
49     );
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function calculateDependencies() {
56     // The empty source plugin supports the entity_type constant.
57     if (isset($this->configuration['constants']['entity_type'])) {
58       $this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
59     }
60     return $this->dependencies;
61   }
62
63 }