diff --git a/core/modules/field/migration_templates/d6_field.yml b/core/modules/field/migration_templates/d6_field.yml index ec29aad..11b185f 100644 --- a/core/modules/field/migration_templates/d6_field.yml +++ b/core/modules/field/migration_templates/d6_field.yml @@ -17,7 +17,7 @@ process: field_name: field_name type: - - plugin: field_type + plugin: d6_field_type source: - type - widget_type diff --git a/core/modules/field/migration_templates/d7_field.yml b/core/modules/field/migration_templates/d7_field.yml index 3b01f54..ba14749 100755 --- a/core/modules/field/migration_templates/d7_field.yml +++ b/core/modules/field/migration_templates/d7_field.yml @@ -13,7 +13,7 @@ process: langcode: 'constants/langcode' field_name: field_name type: - plugin: static_map + plugin: d7_field_type source: type map: date: datetime diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldType.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldType.php index 2c36275..61e0cea 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldType.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldType.php @@ -17,7 +17,7 @@ /** * @MigrateProcessPlugin( - * id = "field_type" + * id = "d6_field_type" * ) */ class FieldType extends StaticMap implements ContainerFactoryPluginInterface { @@ -64,11 +64,11 @@ public static function create(ContainerInterface $container, array $configuratio public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { list ($field_type, $widget_type) = $value; - try { - return $this->cckPluginManager->createInstance($field_type) - ->getFieldType($row); + $cckplugin = $this->cckPluginManager->createInstance($field_type, ['core' => 7]); + if ($cckplugin) { + return $cckplugin->getFieldType($row); } - catch (PluginNotFoundException $e) { + else { return parent::transform($value, $migrate_executable, $row, $destination_property); } } diff --git a/core/modules/field/src/Plugin/migrate/process/d7/FieldType.php b/core/modules/field/src/Plugin/migrate/process/d7/FieldType.php new file mode 100644 index 0000000..7f8c1a2 --- /dev/null +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldType.php @@ -0,0 +1,74 @@ +cckPluginManager = $cck_plugin_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') + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $cckplugin = $this->cckPluginManager->createInstance($value, ['core' => 7]); + if ($cckplugin) { + return $cckplugin->getFieldType($row); + } + else { + return parent::transform($value, $migrate_executable, $row, $destination_property); + } + } + +} diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php index 4e4e456..8ef91fc 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php @@ -13,7 +13,9 @@ /** * @MigrateCckField( - * id = "filefield" + * id = "filefield", + * field_type = "file", + * core = {6} * ) */ class FileField extends CckFieldPluginBase { diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php index d9426fd..249334f 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php @@ -14,6 +14,8 @@ /** * @MigrateCckField( * id = "file", + * field_type = "file", + * core = {7} * ) */ class FileField extends CckFieldPluginBase { diff --git a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php index 327cbda..cfdbd7d 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php @@ -12,7 +12,9 @@ /** * @MigrateCckField( - * id = "link" + * id = "link", + * field_type = "link", + * core = {6} * ) */ class LinkField extends CckFieldPluginBase { diff --git a/core/modules/migrate_drupal/migrate_drupal.services.yml b/core/modules/migrate_drupal/migrate_drupal.services.yml index 2807b5f..71a0b27 100644 --- a/core/modules/migrate_drupal/migrate_drupal.services.yml +++ b/core/modules/migrate_drupal/migrate_drupal.services.yml @@ -1,6 +1,6 @@ services: plugin.manager.migrate.cckfield: - class: Drupal\migrate\Plugin\MigratePluginManager + class: Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager arguments: - cckfield - '@container.namespaces' diff --git a/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php b/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php index b7edf0e..a88a504 100644 --- a/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php +++ b/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php @@ -13,9 +13,10 @@ * Defines a cckfield plugin annotation object. * * cckfield plugins are variously responsible for handling the migration of - * CCK fields from Drupal 6 to Drupal 8. They are allowed to alter CCK-related - * migrations when migrations are being generated, and can compute destination - * field types for individual fields during the actual migration process. + * CCK fields from Drupal 6 to Drupal 8, and Field API fields from Drupal 7 + * to Drupal 8. They are allowed to alter CCK-related migrations when migrations + * are being generated, and can compute destination field types for individual + * fields during the actual migration process. * * Plugin Namespace: Plugin\migrate\cckfield * @@ -24,6 +25,17 @@ class MigrateCckField extends Plugin { /** + * @inheritdoc + */ + public function __construct($values) { + parent::__construct($values); + // Provide default value for core property, in case it's missing. + if (empty($this->definition['core'])) { + $this->definition['core'] = [6]; + } + } + + /** * The plugin ID. * * @var string @@ -37,4 +49,18 @@ class MigrateCckField extends Plugin { */ public $type_map = []; + /** + * The Drupal core version(s) this plugin applies to. + * + * @var int[] + */ + public $core = []; + + /** + * The field type to be migrated. + * + * @var string + */ + public $field_type = ''; + } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php new file mode 100644 index 0000000..82fc3a9 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php @@ -0,0 +1,62 @@ +getDefinitions() as $plugin_id => $definition) { + if (in_array($configuration['core'], $definition['core'])) { + if ($field_type == $definition['field_type'] || $field_type == $plugin_id) { + return parent::createInstance($plugin_id, $configuration, $migration); + } + } + } + return FALSE; + } +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php b/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php index 50b1fcd..b457de5 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php @@ -66,15 +66,17 @@ public static function create(ContainerInterface $container, array $configuratio * * @param string $field_type * The field type (plugin ID). + * @param int $core + * The Drupal core version. * @param \Drupal\migrate\Entity\MigrationInterface|NULL $migration * The migration, if any. * * @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface * The cckfield plugin instance. */ - protected function getCckPlugin($field_type, MigrationInterface $migration = NULL) { + protected function getCckPlugin($field_type, $core = 6, MigrationInterface $migration = NULL) { if (empty($this->cckPluginCache[$field_type])) { - $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $migration); + $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, ['core' => $core], $migration); } return $this->cckPluginCache[$field_type]; } diff --git a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php b/core/modules/node/src/Plugin/migrate/builder/d6/Node.php index 99f8d45..9268ecd 100644 --- a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/builder/d6/Node.php @@ -56,9 +56,9 @@ public function buildMigrations(array $template) { if (isset($fields[$node_type])) { foreach ($fields[$node_type] as $field => $info) { - if ($this->cckPluginManager->hasDefinition($info['type'])) { - $this->getCckPlugin($info['type']) - ->processCckFieldValues($migration, $field, $info); + // Process through a CckFieldPlugin if available. + if ($cckplugin = $this->getCckPlugin($info['type'], 6)) { + $cckplugin->processCckFieldValues($migration, $field, $info); } else { $migration->setProcessOfProperty($field, $field); diff --git a/core/modules/node/src/Plugin/migrate/builder/d7/Node.php b/core/modules/node/src/Plugin/migrate/builder/d7/Node.php index 44b124c..d232480 100644 --- a/core/modules/node/src/Plugin/migrate/builder/d7/Node.php +++ b/core/modules/node/src/Plugin/migrate/builder/d7/Node.php @@ -38,9 +38,9 @@ public function buildMigrations(array $template) { if (isset($fields['node'][$bundle])) { foreach ($fields['node'][$bundle] as $field => $data) { - if ($this->cckPluginManager->hasDefinition($data['type'])) { - $this->getCckPlugin($data['type']) - ->processCckFieldValues($migration, $field, $data); + // Process through a CckFieldPlugin if available. + if ($cckplugin = $this->getCckPlugin($data['type'], 7)) { + $cckplugin->processCckFieldValues($migration, $field, $data); } else { $migration->setProcessOfProperty($field, $field); diff --git a/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php b/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php index d6de1ec..e35c675 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php +++ b/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php @@ -12,7 +12,9 @@ /** * @MigrateCckField( - * id = "taxonomy_term_reference" + * id = "taxonomy_term_reference", + * field_type = "taxonomy_term_reference", + * core = {6,7} * ) */ class TaxonomyTermReference extends CckFieldPluginBase { diff --git a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php index a386b5f..049d913 100644 --- a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php +++ b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php @@ -13,7 +13,9 @@ /** * @MigrateCckField( - * id = "text" + * id = "text", + * field_type = "text", + * core = {6,7} * ) */ class TextField extends CckFieldPluginBase {