diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php index a8e1038..140234f 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php @@ -7,6 +7,11 @@ namespace Drupal\migrate\Plugin\migrate\destination; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\migrate\Entity\MigrationInterface; + /** * @MigrateDestination( * id = "entity:field_storage_config" @@ -15,6 +20,13 @@ class EntityFieldStorageConfig extends EntityConfigBase { /** + * The field type plugin manager. + * + * @var \Drupal\Core\Field\FieldTypePluginManagerInterface + */ + protected $fieldTypePluginManager; + + /** * {@inheritdoc} */ public function getIds() { @@ -24,6 +36,45 @@ public function getIds() { } /** + * Construct a new entity. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param MigrationInterface $migration + * The migration. + * @param EntityStorageInterface $storage + * The storage for this entity type. + * @param array $bundles + * The list of bundles this entity type has. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager + * The field type plugin manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, FieldTypePluginManagerInterface $field_type_plugin_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles); + $this->fieldTypePluginManager = $field_type_plugin_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + $entity_type_id = static::getEntityTypeId($plugin_id); + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('entity.manager')->getStorage($entity_type_id), + array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)), + $container->get('plugin.manager.field.field_type') + ); + } + + /** * {@inheritdoc} */ public function calculateDependencies() { @@ -32,7 +83,7 @@ public function calculateDependencies() { // source plugin configuration. $source_configuration = $this->migration->getSourcePlugin()->getConfiguration(); if (isset($source_configuration['constants']['type'])) { - $field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($source_configuration['constants']['type']); + $field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']); $this->addDependency('module', $field_type['provider']); } return $this->dependencies; diff --git a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php b/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php index 32a9ab7..516cc4a 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php +++ b/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php @@ -7,6 +7,11 @@ namespace Drupal\migrate\Plugin\migrate\source; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\migrate\Entity\MigrationInterface; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; + /** * Source returning an empty row. * @@ -16,7 +21,35 @@ * id = "empty" * ) */ -class EmptySource extends SourcePluginBase { +class EmptySource extends SourcePluginBase implements ContainerFactoryPluginInterface { + + /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('entity.manager') + ); + } /** * {@inheritdoc} @@ -53,4 +86,15 @@ public function count() { return 1; } + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + // The empty source plugin supports the entity_type constant. + if (isset($this->configuration['constants']['entity_type'])) { + $this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider()); + } + return $this->dependencies; + } + } diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php index a238927..366de38 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -83,7 +83,7 @@ protected function getSource($configuration = [], $migrate_config = [], $status ->willReturn($id_map_array); $constructor_args = [$configuration, 'd6_action', [], $this->migration]; - $methods = ['getModuleHandler', 'fields', 'getIds', '__toString', 'getIterator', 'prepareRow', 'initializeIterator']; + $methods = ['getModuleHandler', 'fields', 'getIds', '__toString', 'getIterator', 'prepareRow', 'initializeIterator', 'calculateDependencies']; $source_plugin = $this->getMock('\Drupal\migrate\Plugin\migrate\source\SourcePluginBase', $methods, $constructor_args); $source_plugin diff --git a/core/modules/migrate/tests/src/Unit/SqlBaseTest.php b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php index b526b7c..caa6e3d 100644 --- a/core/modules/migrate/tests/src/Unit/SqlBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php @@ -167,4 +167,11 @@ public function fields() {} */ public function query() {} + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + return []; + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php index cc6f86b..f8e6c3e 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Exception\RequirementsException; @@ -38,6 +39,21 @@ protected $requirements = TRUE; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + $this->entityManager = $entity_manager; + } + + /** * Retrieves all system data information from origin system. * * @return array @@ -69,7 +85,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $migration + $migration, + $container->get('entity.manager') ); } @@ -150,7 +167,7 @@ protected function variableGet($name, $default) { public function calculateDependencies() { // Generic handling for Drupal source plugin constants. if (isset($this->configuration['constants']['entity_type'])) { - $this->addDependency('module', \Drupal::entityManager()->getDefinition($this->configuration['constants']['entity_type'])->getProvider()); + $this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider()); } if (isset($this->configuration['constants']['module'])) { $this->addDependency('module', $this->configuration['constants']['module']); diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php index 32819eb..bdaf981 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php @@ -7,6 +7,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\migrate\Entity\MigrationInterface; /** @@ -31,8 +32,8 @@ class Variable extends DrupalSqlBase { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $entity_manager); $this->variables = $this->configuration['variables']; } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ViewMode.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ViewMode.php index 4b16a66..ea1c505 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ViewMode.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ViewMode.php @@ -7,6 +7,11 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source\d6; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\migrate\Entity\MigrationInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * The view mode source. * @@ -73,7 +78,7 @@ public function getIds() { public function calculateDependencies() { $this->dependencies = parent::calculateDependencies(); if (isset($this->configuration['constants']['targetEntityType'])) { - $this->addDependency('module', \Drupal::entityManager()->getDefinition($this->configuration['constants']['targetEntityType'])->getProvider()); + $this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['targetEntityType'])->getProvider()); } return $this->dependencies; }