diff --git a/core/modules/field/src/Plugin/migrate/process/FieldType.php b/core/modules/field/src/Plugin/migrate/process/FieldType.php index 7874f9c..7085fa4 100644 --- a/core/modules/field/src/Plugin/migrate/process/FieldType.php +++ b/core/modules/field/src/Plugin/migrate/process/FieldType.php @@ -9,6 +9,7 @@ use Drupal\migrate\Plugin\migrate\process\StaticMap; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -26,6 +27,13 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface { protected $cckPluginManager; /** + * The field plugin manager. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface + */ + protected $fieldPluginManager; + + /** * The migration object. * * @var \Drupal\migrate\Plugin\MigrationInterface @@ -43,12 +51,15 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface { * The plugin definition. * @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager * The cckfield plugin manager. + * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager + * The field plugin manager. * @param \Drupal\migrate\Plugin\MigrationInterface $migration * The migration being run. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrationInterface $migration = NULL) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->cckPluginManager = $cck_plugin_manager; + $this->fieldPluginManager = $field_plugin_manager; $this->migration = $migration; } @@ -61,6 +72,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migrate.field'), $migration ); } @@ -76,7 +88,13 @@ public function transform($value, MigrateExecutableInterface $migrate_executable return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row); } catch (PluginNotFoundException $e) { - return parent::transform($value, $migrate_executable, $row, $destination_property); + try { + $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration); + return $this->fieldPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row); + } + catch (PluginNotFoundException $e) { + return parent::transform($value, $migrate_executable, $row, $destination_property); + } } } diff --git a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php index 3fba70a..5447b59 100644 --- a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php @@ -9,6 +9,7 @@ use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\MigrationDeriverTrait; use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -39,6 +40,20 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { protected $cckPluginManager; /** + * Already-instantiated field plugins, keyed by ID. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[] + */ + protected $fieldPluginCache; + + /** + * The field plugin manager. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface + */ + protected $fieldPluginManager; + + /** * Whether or not to include translations. * * @var bool @@ -52,12 +67,15 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { * The base plugin ID for the plugin ID. * @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager * The CCK plugin manager. + * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager + * The field plugin manager. * @param bool $translations * Whether or not to include translations. */ - public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, $translations) { + public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager, $translations) { $this->basePluginId = $base_plugin_id; $this->cckPluginManager = $cck_manager; + $this->fieldPluginManager = $field_manager; $this->includeTranslations = $translations; } @@ -69,6 +87,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migrate.field'), $container->get('module_handler')->moduleExists('content_translation') ); } @@ -90,7 +109,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { return $this->derivatives; } - // Read all CCK field instance definitions in the source database. + // Read all field instance definitions in the source database. $fields = array(); try { $source_plugin = static::getSourcePlugin('d6_field_instance'); @@ -102,7 +121,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { } catch (RequirementsException $e) { // If checkRequirements() failed then the content module did not exist and - // we do not have any CCK fields. Therefore, $fields will be empty and + // we do not have any fields. Therefore, $fields will be empty and // below we'll create a migration just for the node properties. } @@ -125,6 +144,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { $values['migration_dependencies']['required'][] = 'd6_node:' . $node_type; } + /** @var \Drupal\migrate\Plugin\Migration $migration */ $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values); if (isset($fields[$node_type])) { foreach ($fields[$node_type] as $field_name => $info) { @@ -138,7 +158,17 @@ public function getDerivativeDefinitions($base_plugin_definition) { ->processCckFieldValues($migration, $field_name, $info); } catch (PluginNotFoundException $ex) { - $migration->setProcessOfProperty($field_name, $field_name); + try { + $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration); + if (!isset($this->fieldPluginCache[$field_type])) { + $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 6], $migration); + } + $this->fieldPluginCache[$field_type] + ->processFieldValues($migration, $field_name, $info); + } + catch (PluginNotFoundException $ex) { + $migration->setProcessOfProperty($field_name, $field_name); + } } } } diff --git a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php index bd3d8b9..e85b263 100644 --- a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php @@ -9,6 +9,7 @@ use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\MigrationDeriverTrait; use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -39,16 +40,33 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface { protected $cckPluginManager; /** + * Already-instantiated field plugins, keyed by ID. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[] + */ + protected $fieldPluginCache; + + /** + * The field plugin manager. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface + */ + protected $fieldPluginManager; + + /** * D7NodeDeriver constructor. * * @param string $base_plugin_id * The base plugin ID for the plugin ID. * @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager * The CCK plugin manager. + * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager + * The field plugin manager. */ - public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager) { + public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager) { $this->basePluginId = $base_plugin_id; $this->cckPluginManager = $cck_manager; + $this->fieldPluginManager = $field_manager; } /** @@ -57,7 +75,8 @@ public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterfa public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, - $container->get('plugin.manager.migrate.cckfield') + $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migrate.field') ); } @@ -108,7 +127,17 @@ public function getDerivativeDefinitions($base_plugin_definition) { ->processCckFieldValues($migration, $field_name, $info); } catch (PluginNotFoundException $ex) { - $migration->setProcessOfProperty($field_name, $field_name); + try { + $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration); + if (!isset($this->fieldPluginCache[$field_type])) { + $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 7], $migration); + } + $this->fieldPluginCache[$field_type] + ->processFieldValues($migration, $field_name, $info); + } + catch (PluginNotFoundException $ex) { + $migration->setProcessOfProperty($field_name, $field_name); + } } } } diff --git a/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php b/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php index 22280ec..a2e1b5b 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php +++ b/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php @@ -10,12 +10,14 @@ use Drupal\migrate\Plugin\Migration; use Drupal\migrate\Plugin\MigrationDeriverTrait; use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Deriver for Drupal 7 taxonomy term migrations based on vocabularies. */ class D7TaxonomyTermDeriver extends DeriverBase implements ContainerDeriverInterface { + use MigrationDeriverTrait; /** @@ -40,16 +42,33 @@ class D7TaxonomyTermDeriver extends DeriverBase implements ContainerDeriverInter protected $cckPluginManager; /** + * Already-instantiated field plugins, keyed by ID. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[] + */ + protected $fieldPluginCache; + + /** + * The field plugin manager. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface + */ + protected $fieldPluginManager; + + /** * D7TaxonomyTermDeriver constructor. * * @param string $base_plugin_id * The base plugin ID for the plugin ID. * @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager * The CCK plugin manager. + * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager + * The field plugin manager. */ - public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager) { + public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager) { $this->basePluginId = $base_plugin_id; $this->cckPluginManager = $cck_manager; + $this->fieldPluginManager = $field_manager; } /** @@ -58,7 +77,8 @@ public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterfa public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, - $container->get('plugin.manager.migrate.cckfield') + $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migrate.field') ); } @@ -110,7 +130,17 @@ public function getDerivativeDefinitions($base_plugin_definition) { ->processCckFieldValues($migration, $field_name, $info); } catch (PluginNotFoundException $ex) { - $migration->setProcessOfProperty($field_name, $field_name); + try { + $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration); + if (!isset($this->fieldPluginCache[$field_type])) { + $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 7], $migration); + } + $this->fieldPluginCache[$field_type] + ->processFieldValues($migration, $field_name, $info); + } + catch (PluginNotFoundException $ex) { + $migration->setProcessOfProperty($field_name, $field_name); + } } } } diff --git a/core/modules/user/src/Plugin/migrate/User.php b/core/modules/user/src/Plugin/migrate/User.php index d89787c..813c952 100644 --- a/core/modules/user/src/Plugin/migrate/User.php +++ b/core/modules/user/src/Plugin/migrate/User.php @@ -3,12 +3,78 @@ namespace Drupal\user\Plugin\migrate; use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate_drupal\Plugin\migrate\CckMigration; +use Drupal\migrate\Plugin\MigrateDestinationPluginManager; +use Drupal\migrate\Plugin\MigratePluginManager; +use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\migrate\FieldMigration; +use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin class for Drupal 7 user migrations dealing with fields and profiles. */ -class User extends CckMigration { +class User extends FieldMigration { + + /** + * Already-instantiated cckfield plugins, keyed by ID. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[] + */ + protected $cckPluginCache; + + /** + * The cckfield plugin manager. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface + */ + protected $cckPluginManager; + + /** + * Constructs User Migration. + * + * @param array $configuration + * Plugin configuration. + * @param string $plugin_id + * The plugin ID. + * @param mixed $plugin_definition + * The plugin definition. + * @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager + * The cckfield plugin manager. + * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager + * The migration plugin manager. + * @param \Drupal\migrate\Plugin\MigratePluginManager $source_plugin_manager + * The source migration plugin manager. + * @param \Drupal\migrate\Plugin\MigratePluginManager $process_plugin_manager + * The process migration plugin manager. + * @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager + * The destination migration plugin manager. + * @param \Drupal\migrate\Plugin\MigratePluginManager $idmap_plugin_manager + * The ID map migration plugin manager. + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManager $source_plugin_manager, MigratePluginManager $process_plugin_manager, MigrateDestinationPluginManager $destination_plugin_manager, MigratePluginManager $idmap_plugin_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $field_manager, $migration_plugin_manager, $source_plugin_manager, $process_plugin_manager, $destination_plugin_manager, $idmap_plugin_manager); + $this->cckPluginManager = $cck_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migrate.field'), + $container->get('plugin.manager.migration'), + $container->get('plugin.manager.migrate.source'), + $container->get('plugin.manager.migrate.process'), + $container->get('plugin.manager.migrate.destination'), + $container->get('plugin.manager.migrate.id_map') + ); + } /** * {@inheritdoc} @@ -39,7 +105,17 @@ public function getProcess() { ->processCckFieldValues($this, $field_name, $info); } else { - $this->process[$field_name] = $field_name; + if ($this->fieldPluginManager->hasDefinition($field_type)) { + if (!isset($this->fieldPluginCache[$field_type])) { + $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($field_type, [], $this); + } + $info = $row->getSource(); + $this->fieldPluginCache[$field_type] + ->processFieldValues($this, $field_name, $info); + } + else { + $this->process[$field_name] = $field_name; + } } } }