diff --git a/core/modules/migrate/src/Plugin/MigrateSourceInterface.php b/core/modules/migrate/src/Plugin/MigrateSourceInterface.php index 0321ea9..d320c4b 100644 --- a/core/modules/migrate/src/Plugin/MigrateSourceInterface.php +++ b/core/modules/migrate/src/Plugin/MigrateSourceInterface.php @@ -6,8 +6,6 @@ */ namespace Drupal\migrate\Plugin; - -use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\migrate\Row; @@ -21,7 +19,7 @@ * * @ingroup migration */ -interface MigrateSourceInterface extends \Countable, \Iterator, PluginInspectionInterface, DependentPluginInterface { +interface MigrateSourceInterface extends \Countable, \Iterator, PluginInspectionInterface { /** * Returns available fields on the source. @@ -64,12 +62,4 @@ public function __toString(); */ public function getIds(); - /** - * Gets the plugin configuration. - * - * @return array - * The plugin configuration - */ - public function getConfiguration(); - } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php index 140234f..9d1eba3 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php @@ -7,11 +7,6 @@ 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" @@ -20,13 +15,6 @@ class EntityFieldStorageConfig extends EntityConfigBase { /** - * The field type plugin manager. - * - * @var \Drupal\Core\Field\FieldTypePluginManagerInterface - */ - protected $fieldTypePluginManager; - - /** * {@inheritdoc} */ public function getIds() { @@ -35,58 +23,4 @@ public function getIds() { return $ids; } - /** - * 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() { - $this->dependencies = parent::calculateDependencies(); - // Add a dependency on the module that provides the field type using the - // source plugin configuration. - $source_configuration = $this->migration->getSourcePlugin()->getConfiguration(); - if (isset($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 516cc4a..32a9ab7 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php +++ b/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php @@ -7,11 +7,6 @@ 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. * @@ -21,35 +16,7 @@ * id = "empty" * ) */ -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') - ); - } +class EmptySource extends SourcePluginBase { /** * {@inheritdoc} @@ -86,15 +53,4 @@ 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/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index fdd4238..2ebcbba 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -7,7 +7,6 @@ namespace Drupal\migrate\Plugin\migrate\source; -use Drupal\Core\Entity\DependencyTrait; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateException; @@ -27,8 +26,6 @@ */ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInterface { - use DependencyTrait; - /** * @var \Drupal\Core\Extension\ModuleHandlerInterface */ @@ -458,11 +455,4 @@ protected function getCache() { return $this->cache; } - /** - * {@inheritdoc} - */ - public function getConfiguration() { - return $this->configuration; - } - } diff --git a/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php index 22863aa..16d7e0b 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php @@ -70,6 +70,7 @@ */ protected function setUp() { $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); + $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); $migration = $this->getMigration(); $migration->expects($this->any()) @@ -77,7 +78,7 @@ protected function setUp() { ->will($this->returnValue(static::ORIGINAL_HIGH_WATER)); // Need the test class, not the original because we need a setDatabase method. This is not pretty :/ $plugin_class = preg_replace('/^Drupal\\\\(\w+)\\\\Plugin\\\\migrate(\\\\source(\\\\.+)?\\\\)([^\\\\]+)$/', 'Drupal\\Tests\\\$1\\Unit$2Test$4', static::PLUGIN_CLASS); - $plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration); + $plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $entity_manager); $plugin->setDatabase($this->getDatabase($this->databaseContents + array('test_map' => array()))); $plugin->setModuleHandler($module_handler); $plugin->setStringTranslation($this->getStringTranslationStub()); diff --git a/core/modules/migrate_drupal/migrate_drupal.module b/core/modules/migrate_drupal/migrate_drupal.module index fd4ccbc..4fb6cf4 100644 --- a/core/modules/migrate_drupal/migrate_drupal.module +++ b/core/modules/migrate_drupal/migrate_drupal.module @@ -29,3 +29,17 @@ function migrate_drupal_help($route_name, RouteMatchInterface $route_match) { return $output; } } + +/** + * Implements hook_migrate_destination_info_alter(). + */ +function migrate_drupal_migrate_destination_info_alter(&$definitions) { + $definitions['entity:field_storage_config']['class'] = 'Drupal\migrate_drupal\Plugin\migrate\destination\EntityFieldStorageConfig'; +} + +/** + * Implements hook_migrate_source_info_alter(). + */ +function migrate_drupal_migrate_source_info_alter(&$definitions) { + $definitions['empty']['class'] = 'Drupal\migrate_drupal\Plugin\migrate\source\EmptySource'; +} diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php similarity index 81% copy from core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php copy to core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php index 140234f..4f65828 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php @@ -2,22 +2,21 @@ /** * @file - * Contains \Drupal\migrate\Plugin\migrate\destination\EntityFieldEntity. + * Contains \Drupal\migrate_drupal\Plugin\migrate\destination\EntityFieldEntity. */ -namespace Drupal\migrate\Plugin\migrate\destination; +namespace Drupal\migrate_drupal\Plugin\migrate\destination; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate_drupal\Entity\MigrationInterface; +use Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig as BaseEntityFieldStorageConfig; /** - * @MigrateDestination( - * id = "entity:field_storage_config" - * ) + * Migrate Drupal specific Dependencies. */ -class EntityFieldStorageConfig extends EntityConfigBase { +class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig { /** * The field type plugin manager. @@ -27,16 +26,7 @@ class EntityFieldStorageConfig extends EntityConfigBase { protected $fieldTypePluginManager; /** - * {@inheritdoc} - */ - public function getIds() { - $ids['entity_type']['type'] = 'string'; - $ids['field_name']['type'] = 'string'; - return $ids; - } - - /** - * Construct a new entity. + * Construct a new plugin. * * @param array $configuration * A configuration array containing information about the plugin instance. @@ -81,7 +71,7 @@ public function calculateDependencies() { $this->dependencies = parent::calculateDependencies(); // Add a dependency on the module that provides the field type using the // source plugin configuration. - $source_configuration = $this->migration->getSourcePlugin()->getConfiguration(); + $source_configuration = $this->migration->get('source'); if (isset($source_configuration['constants']['type'])) { $field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']); $this->addDependency('module', $field_type['provider']); 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 f8e6c3e..85020fe 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php @@ -7,7 +7,9 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\Entity\DependencyTrait; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Entity\MigrationInterface; @@ -22,7 +24,9 @@ * Mainly to let children retrieve information from the origin system in an * easier way. */ -abstract class DrupalSqlBase extends SqlBase implements ContainerFactoryPluginInterface, RequirementsInterface { +abstract class DrupalSqlBase extends SqlBase implements ContainerFactoryPluginInterface, RequirementsInterface, DependentPluginInterface { + + use DependencyTrait; /** * The contents of the system table. diff --git a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php similarity index 60% copy from core/modules/migrate/src/Plugin/migrate/source/EmptySource.php copy to core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php index 516cc4a..d07d19b 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php @@ -2,26 +2,26 @@ /** * @file - * Contains \Drupal\migrate\Plugin\migrate\source\Constants. + * Contains \Drupal\migrate_drupal\Plugin\migrate\source\EmptySource. */ -namespace Drupal\migrate\Plugin\migrate\source; +namespace Drupal\migrate_drupal\Plugin\migrate\source; +use Drupal\Component\Plugin\DependentPluginInterface; +use Drupal\Core\Entity\DependencyTrait; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate_drupal\Entity\MigrationInterface; +use Drupal\migrate\Plugin\migrate\source\EmptySource as BaseEmptySource; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; + /** - * Source returning an empty row. - * - * This is generally useful when needing to create a field using a migration.. - * - * @MigrateSource( - * id = "empty" - * ) + * Source returning an empty row with Migrate Drupal speicfic dependencies. */ -class EmptySource extends SourcePluginBase implements ContainerFactoryPluginInterface { +class EmptySource extends BaseEmptySource implements ContainerFactoryPluginInterface, DependentPluginInterface { + + use DependencyTrait; /** * The entity manager. @@ -54,41 +54,6 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function fields() { - return array( - 'id' => t('ID'), - ); - } - - /** - * {@inheritdoc} - */ - public function initializeIterator() { - return new \ArrayIterator(array(array('id' => ''))); - } - - public function __toString() { - return ''; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['id']['type'] = 'string'; - return $ids; - } - - /** - * {@inheritdoc} - */ - 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'])) {