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..94f1675 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 @@ -22,7 +22,6 @@ process: email: email file: file image: image - link_field: link list_boolean: boolean list_integer: list_integer list_text: list_string @@ -30,10 +29,6 @@ process: number_decimal: decimal number_float: float phone: telephone - taxonomy_term_reference: entity_reference - text: text - text_long: text_long - text_with_summary: text_with_summary translatable: translatable cardinality: cardinality settings: 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..4811548 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' => 6]); + 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..a22f98e --- /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) { + if ($cckplugin->getFieldType($row)) { + return $cckplugin->getFieldType($row); + } + } + 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..450062b 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 = "filefield", + * 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/file/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php index e818d70..e73aaba 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php @@ -12,7 +12,9 @@ /** * @MigrateCckField( - * id = "image" + * id = "image", + * field_type = "file", + * core = {7} * ) */ class ImageField 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..d7d042d 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php @@ -12,7 +12,12 @@ /** * @MigrateCckField( - * id = "link" + * id = "link", + * field_type = "link", + * core = {6,7}, + * type_map = { + * "link_field" = "link" + * } * ) */ 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..20e440d --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php @@ -0,0 +1,43 @@ +getDefinitions() as $plugin_id => $definition) { + if (in_array($configuration['core'], $definition['core'])) { + if (array_key_exists($field_type, $definition['type_map']) || $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/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php b/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php index 30b739e..f4cd31d 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php @@ -57,7 +57,7 @@ public function buildMigrations(array $template) { // Allow the cckfield plugin to alter the migration as necessary so that // it knows how to handle fields of this type. $this->cckPluginManager - ->createInstance($field_type, [], $migration) + ->createInstance($field_type, ['core' => 6], $migration) ->{$this->configuration['cck_plugin_method']}($migration); } } 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..4fed4d3 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,11 @@ public function buildMigrations(array $template) { if (isset($fields['node'][$bundle])) { foreach ($fields['node'][$bundle] as $field => $data) { + // Process through a CckFieldPlugin if available. if ($this->cckPluginManager->hasDefinition($data['type'])) { - $this->getCckPlugin($data['type']) - ->processCckFieldValues($migration, $field, $data); + 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..0b59848 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php +++ b/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php @@ -12,7 +12,12 @@ /** * @MigrateCckField( - * id = "taxonomy_term_reference" + * id = "taxonomy_term_reference", + * field_type = "taxonomy_term_reference", + * type_map = { + * "taxonomy_term_reference" = "entity_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..d17a0b1 100644 --- a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php +++ b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php @@ -13,7 +13,14 @@ /** * @MigrateCckField( - * id = "text" + * id = "text", + * field_type = "text", + * type_map = { + * "text" = "text", + * "text_long" = "text_long", + * "text_with_summary" = "text_with_summary" + * }, + * core = {6,7} * ) */ class TextField extends CckFieldPluginBase { @@ -118,6 +125,7 @@ public function getFieldType(Row $row) { case 'text_textarea': return 'text_long'; default: + return parent::getFieldType($row); break; } }