Version 1
[yaffs-website] / web / core / modules / migrate / src / Plugin / MigrateDestinationPluginManager.php
1 <?php
2
3 namespace Drupal\migrate\Plugin;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8
9 /**
10  * Plugin manager for migrate destination plugins.
11  *
12  * @see \Drupal\migrate\Plugin\MigrateDestinationInterface
13  * @see \Drupal\migrate\Plugin\destination\DestinationBase
14  * @see \Drupal\migrate\Annotation\MigrateDestination
15  * @see plugin_api
16  *
17  * @ingroup migration
18  */
19 class MigrateDestinationPluginManager extends MigratePluginManager {
20
21   /**
22    * The entity manager.
23    *
24    * @var \Drupal\Core\Entity\EntityManagerInterface
25    */
26   protected $entityManager;
27
28   /**
29    * Constructs a MigrateDestinationPluginManager object.
30    *
31    * @param string $type
32    *   The type of the plugin: row, source, process, destination, entity_field,
33    *   id_map.
34    * @param \Traversable $namespaces
35    *   An object that implements \Traversable which contains the root paths
36    *   keyed by the corresponding namespace to look for plugin implementations.
37    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
38    *   Cache backend instance to use.
39    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
40    *   The module handler to invoke the alter hook with.
41    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
42    *   The entity manager.
43    * @param string $annotation
44    *   (optional) The annotation class name. Defaults to
45    *   'Drupal\migrate\Annotation\MigrateDestination'.
46    */
47   public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager, $annotation = 'Drupal\migrate\Annotation\MigrateDestination') {
48     parent::__construct($type, $namespaces, $cache_backend, $module_handler, $annotation);
49     $this->entityManager = $entity_manager;
50   }
51
52   /**
53    * {@inheritdoc}
54    *
55    * A specific createInstance method is necessary to pass the migration on.
56    */
57   public function createInstance($plugin_id, array $configuration = [], MigrationInterface $migration = NULL) {
58     if (substr($plugin_id, 0, 7) == 'entity:' && !$this->entityManager->getDefinition(substr($plugin_id, 7), FALSE)) {
59       $plugin_id = 'null';
60     }
61     return parent::createInstance($plugin_id, $configuration, $migration);
62   }
63
64 }