From 24f816a11cc18416fcf0775968c76e51716f0682 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 11 Oct 2016 12:43:56 +0100 Subject: [PATCH] Issue #2683435 by hussainweb, mikeryan, quietone, alexpott, michael_wojcik, phenaproxima, benjy: Consider renaming Migrate's cckfield plugins --- .../field/migration_templates/d6_field.yml | 4 +- .../d6_field_formatter_settings.yml | 4 +- .../migration_templates/d6_field_instance.yml | 4 +- .../d6_field_instance_widget_settings.yml | 4 +- .../field/migration_templates/d7_field.yml | 4 +- .../d7_field_formatter_settings.yml | 4 +- .../migration_templates/d7_field_instance.yml | 4 +- .../d7_field_instance_widget_settings.yml | 4 +- .../src/Plugin/migrate/process/FieldType.php | 22 +-- .../{cckfield => field}/d6/FileField.php | 12 +- .../{cckfield => field}/d7/FileField.php | 10 +- .../{cckfield => field}/d7/ImageField.php | 10 +- .../src/Plugin/migrate/process/d6/CckFile.php | 99 +----------- .../Plugin/migrate/process/d6/FieldFile.php | 104 +++++++++++++ .../d6/{CckFileTest.php => FieldFileTest.php} | 6 +- .../migrate/{cckfield => field}/LinkField.php | 14 +- .../{cckfield => field}/d7/LinkField.php | 6 +- .../src/Plugin/migrate/process/d6/CckLink.php | 81 +--------- .../Plugin/migrate/process/d6/FieldLink.php | 86 +++++++++++ .../d6/{CckLinkTest.php => FieldLinkTest.php} | 8 +- .../migrate_drupal.services.yml | 9 ++ .../src/Annotation/MigrateCckField.php | 45 +----- .../src/Annotation/MigrateField.php | 54 +++++++ .../src/Plugin/MigrateCckFieldInterface.php | 85 +---------- .../Plugin/MigrateCckFieldPluginManager.php | 50 +----- .../MigrateCckFieldPluginManagerInterface.php | 31 +--- .../src/Plugin/MigrateFieldInterface.php | 87 +++++++++++ .../src/Plugin/MigrateFieldPluginManager.php | 55 +++++++ .../MigrateFieldPluginManagerInterface.php | 28 ++++ .../src/Plugin/migrate/CckMigration.php | 126 +-------------- .../src/Plugin/migrate/FieldMigration.php | 144 ++++++++++++++++++ .../migrate/cckfield/CckFieldPluginBase.php | 78 +--------- .../Plugin/migrate/field/FieldPluginBase.php | 83 ++++++++++ ...rate_cckfield_plugin_manager_test.info.yml | 6 - .../Plugin/migrate/cckfield/D6FileField.php | 29 ---- .../cckfield/D6NoCoreVersionSpecified.php | 25 --- ...migrate_field_plugin_manager_test.info.yml | 6 + .../src/Plugin/migrate/field/D6FileField.php | 31 ++++ .../field/D6NoCoreVersionSpecified.php | 27 ++++ ....php => MigrateFieldPluginManagerTest.php} | 12 +- .../node/src/Plugin/migrate/D6NodeDeriver.php | 38 ++--- .../node/src/Plugin/migrate/D7NodeDeriver.php | 34 ++--- .../src/Plugin/migrate/source/d6/Node.php | 39 +++-- .../TaxonomyTermReference.php | 10 +- .../migrate/{cckfield => field}/TextField.php | 10 +- .../tests/src/Unit/Migrate/TextFieldTest.php | 20 +-- core/modules/user/src/Plugin/migrate/User.php | 2 +- 47 files changed, 904 insertions(+), 750 deletions(-) rename core/modules/file/src/Plugin/migrate/{cckfield => field}/d6/FileField.php (74%) rename core/modules/file/src/Plugin/migrate/{cckfield => field}/d7/FileField.php (79%) rename core/modules/file/src/Plugin/migrate/{cckfield => field}/d7/ImageField.php (66%) create mode 100644 core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php rename core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/{CckFileTest.php => FieldFileTest.php} (86%) rename core/modules/link/src/Plugin/migrate/{cckfield => field}/LinkField.php (63%) rename core/modules/link/src/Plugin/migrate/{cckfield => field}/d7/LinkField.php (78%) create mode 100644 core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php rename core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/{CckLinkTest.php => FieldLinkTest.php} (81%) create mode 100644 core/modules/migrate_drupal/src/Annotation/MigrateField.php create mode 100644 core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php create mode 100644 core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php create mode 100644 core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManagerInterface.php create mode 100644 core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php create mode 100644 core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php delete mode 100644 core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/migrate_cckfield_plugin_manager_test.info.yml delete mode 100644 core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/src/Plugin/migrate/cckfield/D6FileField.php delete mode 100644 core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/src/Plugin/migrate/cckfield/D6NoCoreVersionSpecified.php create mode 100644 core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/migrate_field_plugin_manager_test.info.yml create mode 100644 core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6FileField.php create mode 100644 core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6NoCoreVersionSpecified.php rename core/modules/migrate_drupal/tests/src/Kernel/{MigrateCckFieldPluginManagerTest.php => MigrateFieldPluginManagerTest.php} (80%) rename core/modules/taxonomy/src/Plugin/migrate/{cckfield => field}/TaxonomyTermReference.php (65%) rename core/modules/text/src/Plugin/migrate/{cckfield => field}/TextField.php (91%) diff --git a/core/modules/field/migration_templates/d6_field.yml b/core/modules/field/migration_templates/d6_field.yml index 531bc132d1..4f68e42848 100644 --- a/core/modules/field/migration_templates/d6_field.yml +++ b/core/modules/field/migration_templates/d6_field.yml @@ -2,8 +2,8 @@ id: d6_field label: Field configuration migration_tags: - Drupal 6 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processField +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processField source: plugin: d6_field constants: diff --git a/core/modules/field/migration_templates/d6_field_formatter_settings.yml b/core/modules/field/migration_templates/d6_field_formatter_settings.yml index 7496db3931..5140f21e5d 100644 --- a/core/modules/field/migration_templates/d6_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d6_field_formatter_settings.yml @@ -2,8 +2,8 @@ id: d6_field_formatter_settings label: Field formatter configuration migration_tags: - Drupal 6 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processFieldFormatter +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processFieldFormatter source: plugin: d6_field_instance_per_view_mode constants: diff --git a/core/modules/field/migration_templates/d6_field_instance.yml b/core/modules/field/migration_templates/d6_field_instance.yml index b5035c2a57..726e4663d1 100644 --- a/core/modules/field/migration_templates/d6_field_instance.yml +++ b/core/modules/field/migration_templates/d6_field_instance.yml @@ -2,8 +2,8 @@ id: d6_field_instance label: Field instance configuration migration_tags: - Drupal 6 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processFieldInstance +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processFieldInstance source: plugin: d6_field_instance constants: diff --git a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml index 46b7d75989..984872dd1a 100644 --- a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml @@ -2,8 +2,8 @@ id: d6_field_instance_widget_settings label: Field instance widget configuration migration_tags: - Drupal 6 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processFieldWidget +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processFieldWidget source: plugin: d6_field_instance_per_form_display constants: diff --git a/core/modules/field/migration_templates/d7_field.yml b/core/modules/field/migration_templates/d7_field.yml index 18135affbb..8836502c22 100644 --- a/core/modules/field/migration_templates/d7_field.yml +++ b/core/modules/field/migration_templates/d7_field.yml @@ -2,8 +2,8 @@ id: d7_field label: Field configuration migration_tags: - Drupal 7 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processField +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processField source: plugin: d7_field constants: diff --git a/core/modules/field/migration_templates/d7_field_formatter_settings.yml b/core/modules/field/migration_templates/d7_field_formatter_settings.yml index ee07ec4be0..f82d92d95a 100644 --- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml @@ -2,8 +2,8 @@ id: d7_field_formatter_settings label: Field formatter configuration migration_tags: - Drupal 7 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processFieldFormatter +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processFieldFormatter source: plugin: d7_field_instance_per_view_mode constants: diff --git a/core/modules/field/migration_templates/d7_field_instance.yml b/core/modules/field/migration_templates/d7_field_instance.yml index b6d2497e53..4996af623b 100644 --- a/core/modules/field/migration_templates/d7_field_instance.yml +++ b/core/modules/field/migration_templates/d7_field_instance.yml @@ -2,8 +2,8 @@ id: d7_field_instance label: Field instance configuration migration_tags: - Drupal 7 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processFieldInstance +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processFieldInstance source: plugin: d7_field_instance constants: diff --git a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml index f88f2d2057..3626346496 100644 --- a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml @@ -2,8 +2,8 @@ id: d7_field_instance_widget_settings label: Field instance widget configuration migration_tags: - Drupal 7 -class: Drupal\migrate_drupal\Plugin\migrate\CckMigration -cck_plugin_method: processFieldWidget +class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration +field_plugin_method: processFieldWidget source: plugin: d7_field_instance_per_form_display constants: diff --git a/core/modules/field/src/Plugin/migrate/process/FieldType.php b/core/modules/field/src/Plugin/migrate/process/FieldType.php index 7874f9c3b7..27ccb526fb 100644 --- a/core/modules/field/src/Plugin/migrate/process/FieldType.php +++ b/core/modules/field/src/Plugin/migrate/process/FieldType.php @@ -8,7 +8,7 @@ use Drupal\migrate\Plugin\MigrationInterface; 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; /** @@ -19,11 +19,11 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface { /** - * The cckfield plugin manager. + * The field plugin manager. * - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface */ - protected $cckPluginManager; + protected $fieldPluginManager; /** * The migration object. @@ -41,14 +41,14 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface { * The plugin ID. * @param mixed $plugin_definition * 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, 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; } @@ -60,7 +60,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migrate.field'), $migration ); } @@ -72,8 +72,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $field_type = is_array($value) ? $value[0] : $value; try { - $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration); - return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row); + $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/file/src/Plugin/migrate/cckfield/d6/FileField.php b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php similarity index 74% rename from core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php rename to core/modules/file/src/Plugin/migrate/field/d6/FileField.php index d63b9c2901..930c13b030 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php +++ b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php @@ -1,18 +1,18 @@ 'd6_cck_file', + 'plugin' => 'd6_field_file', 'source' => $field_name, ]; $migration->mergeProcessOfProperty($field_name, $process); diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php b/core/modules/file/src/Plugin/migrate/field/d7/FileField.php similarity index 79% rename from core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php rename to core/modules/file/src/Plugin/migrate/field/d7/FileField.php index d0b1335e80..8430c8b8b0 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php +++ b/core/modules/file/src/Plugin/migrate/field/d7/FileField.php @@ -1,18 +1,18 @@ 'iterator', 'source' => $field_name, diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php similarity index 66% rename from core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php rename to core/modules/file/src/Plugin/migrate/field/d7/ImageField.php index 7f47caa96e..f63cde2bae 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php @@ -1,17 +1,17 @@ 'iterator', 'source' => $field_name, diff --git a/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php b/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php index fd2f42c3f9..1519851259 100644 --- a/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php +++ b/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php @@ -2,103 +2,12 @@ namespace Drupal\file\Plugin\migrate\process\d6; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\MigrateSkipRowException; -use Drupal\migrate\Plugin\MigrateProcessInterface; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\Row; -use Symfony\Component\DependencyInjection\ContainerInterface; - /** + * @deprecated in Drupal 8.2.x and will be removed before Drupal 9.0.x. Use the + * d6_field_file plugin instead. + * * @MigrateProcessPlugin( * id = "d6_cck_file" * ) */ -class CckFile extends ProcessPluginBase implements ContainerFactoryPluginInterface { - - /** - * The migration process plugin, configured for lookups in d6_file. - * - * @var \Drupal\migrate\Plugin\MigrateProcessInterface - */ - protected $migrationPlugin; - - /** - * Constructs a CckFile plugin instance. - * - * @param array $configuration - * The plugin configuration. - * @param string $plugin_id - * The plugin ID. - * @param mixed $plugin_definition - * The plugin definition. - * @param \Drupal\migrate\Plugin\MigrationInterface $migration - * The current migration. - * @param \Drupal\migrate\Plugin\MigrateProcessInterface $migration_plugin - * An instance of the 'migration' process plugin. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->migration = $migration; - $this->migrationPlugin = $migration_plugin; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { - // Configure the migration process plugin to look up migrated IDs from - // the d6_file migration. - $migration_plugin_configuration = [ - 'source' => ['fid'], - 'migration' => 'd6_file', - ]; - - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $migration, - $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration) - ); - } - - /** - * {@inheritdoc} - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - $options = unserialize($value['data']); - - // Try to look up the ID of the migrated file. If one cannot be found, it - // means the file referenced by the current field item did not migrate for - // some reason -- file migration is notoriously brittle -- and we do NOT - // want to send invalid file references into the field system (it causes - // fatals), so return an empty item instead. - try { - $fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property); - } - // If the migration plugin completely fails its lookup process, it will - // throw a MigrateSkipRowException. It shouldn't, but that is being dealt - // with at https://www.drupal.org/node/2487568. Until that lands, return - // an empty item. - catch (MigrateSkipRowException $e) { - return []; - } - - if ($fid) { - return [ - 'target_id' => $fid, - 'display' => $value['list'], - 'description' => isset($options['description']) ? $options['description'] : '', - 'alt' => isset($options['alt']) ? $options['alt'] : '', - 'title' => isset($options['title']) ? $options['title'] : '', - ]; - } - else { - return []; - } - } - -} +class CckFile extends FieldFile { } diff --git a/core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php b/core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php new file mode 100644 index 0000000000..165b47c91a --- /dev/null +++ b/core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php @@ -0,0 +1,104 @@ +migration = $migration; + $this->migrationPlugin = $migration_plugin; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + // Configure the migration process plugin to look up migrated IDs from + // the d6_file migration. + $migration_plugin_configuration = [ + 'source' => ['fid'], + 'migration' => 'd6_file', + ]; + + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration) + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $options = unserialize($value['data']); + + // Try to look up the ID of the migrated file. If one cannot be found, it + // means the file referenced by the current field item did not migrate for + // some reason -- file migration is notoriously brittle -- and we do NOT + // want to send invalid file references into the field system (it causes + // fatals), so return an empty item instead. + try { + $fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property); + } + // If the migration plugin completely fails its lookup process, it will + // throw a MigrateSkipRowException. It shouldn't, but that is being dealt + // with at https://www.drupal.org/node/2487568. Until that lands, return + // an empty item. + catch (MigrateSkipRowException $e) { + return []; + } + + if ($fid) { + return [ + 'target_id' => $fid, + 'display' => $value['list'], + 'description' => isset($options['description']) ? $options['description'] : '', + 'alt' => isset($options['alt']) ? $options['alt'] : '', + 'title' => isset($options['title']) ? $options['title'] : '', + ]; + } + else { + return []; + } + } + +} diff --git a/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/FieldFileTest.php similarity index 86% rename from core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php rename to core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/FieldFileTest.php index 1ee73a83ee..c807b4fbdd 100644 --- a/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php +++ b/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/FieldFileTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6; -use Drupal\file\Plugin\migrate\process\d6\CckFile; +use Drupal\file\Plugin\migrate\process\d6\FieldFile; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Plugin\MigrateProcessInterface; @@ -12,7 +12,7 @@ /** * @group file */ -class CckFileTest extends UnitTestCase { +class FieldFileTest extends UnitTestCase { /** * Tests that alt and title attributes are included in transformed values. @@ -25,7 +25,7 @@ public function testTransformAltTitle() { $migration_plugin = $this->prophesize(MigrateProcessInterface::class); $migration_plugin->transform(1, $executable, $row, 'foo')->willReturn(1); - $plugin = new CckFile(array(), 'd6_cck_file', array(), $migration, $migration_plugin->reveal()); + $plugin = new FieldFile(array(), 'd6_field_file', array(), $migration, $migration_plugin->reveal()); $options = array( 'alt' => 'Foobaz', diff --git a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php b/core/modules/link/src/Plugin/migrate/field/LinkField.php similarity index 63% rename from core/modules/link/src/Plugin/migrate/cckfield/LinkField.php rename to core/modules/link/src/Plugin/migrate/field/LinkField.php index 314e8df8a6..0a506bf2bb 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/field/LinkField.php @@ -1,12 +1,12 @@ 'link', @@ -37,9 +37,9 @@ public function getFieldFormatterMap() { /** * {@inheritdoc} */ - public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { + public function processFieldValues(MigrationInterface $migration, $field_name, $data) { $process = [ - 'plugin' => 'd6_cck_link', + 'plugin' => 'd6_field_link', 'source' => $field_name, ]; $migration->mergeProcessOfProperty($field_name, $process); diff --git a/core/modules/link/src/Plugin/migrate/cckfield/d7/LinkField.php b/core/modules/link/src/Plugin/migrate/field/d7/LinkField.php similarity index 78% rename from core/modules/link/src/Plugin/migrate/cckfield/d7/LinkField.php rename to core/modules/link/src/Plugin/migrate/field/d7/LinkField.php index 3d657baa5b..64a10ba733 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/d7/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/field/d7/LinkField.php @@ -1,11 +1,11 @@ migration = $migration; - } - - /** - * {@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 - ); - } - - /** - * Turn a Drupal 6 URI into a Drupal 8-compatible format. - * - * @param string $uri - * The 'url' value from Drupal 6. - * - * @return string - * The Drupal 8-compatible URI. - * - * @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri() - */ - protected function canonicalizeUri($uri) { - // If we already have a scheme, we're fine. - if (empty($uri) || !is_null(parse_url($uri, PHP_URL_SCHEME))) { - return $uri; - } - - // Remove the component of the URL. - if (strpos($uri, '') === 0) { - $uri = substr($uri, strlen('')); - } - - // Add the internal: scheme and ensure a leading slash. - return 'internal:/' . ltrim($uri, '/'); - } - - /** - * {@inheritdoc} - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - $attributes = unserialize($value['attributes']); - // Drupal 6 link attributes might be double serialized. - if (!is_array($attributes)) { - $attributes = unserialize($attributes); - } - - if (!$attributes) { - $attributes = []; - } - - // Massage the values into the correct form for the link. - $route['uri'] = $this->canonicalizeUri($value['url']); - $route['options']['attributes'] = $attributes; - $route['title'] = $value['title']; - return $route; - } - -} +class CckLink extends FieldLink { } diff --git a/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php b/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php new file mode 100644 index 0000000000..4badcb6c66 --- /dev/null +++ b/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php @@ -0,0 +1,86 @@ +migration = $migration; + } + + /** + * {@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 + ); + } + + /** + * Turn a Drupal 6 URI into a Drupal 8-compatible format. + * + * @param string $uri + * The 'url' value from Drupal 6. + * + * @return string + * The Drupal 8-compatible URI. + * + * @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri() + */ + protected function canonicalizeUri($uri) { + // If we already have a scheme, we're fine. + if (empty($uri) || !is_null(parse_url($uri, PHP_URL_SCHEME))) { + return $uri; + } + + // Remove the component of the URL. + if (strpos($uri, '') === 0) { + $uri = substr($uri, strlen('')); + } + + // Add the internal: scheme and ensure a leading slash. + return 'internal:/' . ltrim($uri, '/'); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $attributes = unserialize($value['attributes']); + // Drupal 6 link attributes might be double serialized. + if (!is_array($attributes)) { + $attributes = unserialize($attributes); + } + + if (!$attributes) { + $attributes = []; + } + + // Massage the values into the correct form for the link. + $route['uri'] = $this->canonicalizeUri($value['url']); + $route['options']['attributes'] = $attributes; + $route['title'] = $value['title']; + return $route; + } + +} diff --git a/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/CckLinkTest.php b/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/FieldLinkTest.php similarity index 81% rename from core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/CckLinkTest.php rename to core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/FieldLinkTest.php index a96287aeba..4b4eda2249 100644 --- a/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/CckLinkTest.php +++ b/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/FieldLinkTest.php @@ -2,21 +2,21 @@ namespace Drupal\Tests\link\Unit\Plugin\migrate\process\d6; -use Drupal\link\Plugin\migrate\process\d6\CckLink; +use Drupal\link\Plugin\migrate\process\d6\FieldLink; use Drupal\Tests\UnitTestCase; /** * @group Link */ -class CckLinkTest extends UnitTestCase { +class FieldLinkTest extends UnitTestCase { /** - * Test the url transformations in the CckLink process plugin. + * Test the url transformations in the FieldLink process plugin. * * @dataProvider canonicalizeUriDataProvider */ public function testCanonicalizeUri($url, $expected) { - $link_plugin = new CckLink([], '', [], $this->getMock('\Drupal\migrate\Plugin\MigrationInterface')); + $link_plugin = new FieldLink([], '', [], $this->getMock('\Drupal\migrate\Plugin\MigrationInterface')); $transformed = $link_plugin->transform([ 'url' => $url, 'title' => '', diff --git a/core/modules/migrate_drupal/migrate_drupal.services.yml b/core/modules/migrate_drupal/migrate_drupal.services.yml index 71a0b27782..d22788f81a 100644 --- a/core/modules/migrate_drupal/migrate_drupal.services.yml +++ b/core/modules/migrate_drupal/migrate_drupal.services.yml @@ -1,4 +1,13 @@ services: + plugin.manager.migrate.field: + class: Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager + arguments: + - field + - '@container.namespaces' + - '@cache.discovery' + - '@module_handler' + - '\Drupal\migrate_drupal\Annotation\MigrateField' + # @deprecated in 8.2.x, to be removed before 9.0.x. plugin.manager.migrate.cckfield: class: Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager arguments: diff --git a/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php b/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php index 5e5a500467..39edf3e7ea 100644 --- a/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php +++ b/core/modules/migrate_drupal/src/Annotation/MigrateCckField.php @@ -2,53 +2,16 @@ namespace Drupal\migrate_drupal\Annotation; -use Drupal\Component\Annotation\Plugin; - /** - * Defines a cckfield plugin annotation object. + * Deprecated: Defines a cckfield plugin annotation object. * - * cckfield plugins are variously responsible for handling the migration of - * 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. + * @deprecated in Drupal 8.2.x, to be removed before Drupal 9.0.x. Use + * \Drupal\migrate_drupal\Annotation\MigrateField instead. * * Plugin Namespace: Plugin\migrate\cckfield * * @Annotation */ -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 - */ - public $id; - - /** - * Map of D6 and D7 field types to D8 field type plugin IDs. - * - * @var string[] - */ - public $type_map = []; - - /** - * The Drupal core version(s) this plugin applies to. - * - * @var int[] - */ - public $core = []; +class MigrateCckField extends MigrateField { } diff --git a/core/modules/migrate_drupal/src/Annotation/MigrateField.php b/core/modules/migrate_drupal/src/Annotation/MigrateField.php new file mode 100644 index 0000000000..ad78bc924d --- /dev/null +++ b/core/modules/migrate_drupal/src/Annotation/MigrateField.php @@ -0,0 +1,54 @@ +definition['core'])) { + $this->definition['core'] = [6]; + } + } + + /** + * The plugin ID. + * + * @var string + */ + public $id; + + /** + * Map of D6 and D7 field types to D8 field type plugin IDs. + * + * @var string[] + */ + public $type_map = []; + + /** + * The Drupal core version(s) this plugin applies to. + * + * @var int[] + */ + public $core = []; + +} diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php index b30b2b81c3..6d270b7870 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php @@ -2,86 +2,11 @@ namespace Drupal\migrate_drupal\Plugin; -use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\Row; /** - * Provides an interface for all CCK field type plugins. + * Provides an interface for all field type plugins. + * + * @deprecated in Drupal 8.2.x, to be removed before Drupal 9.0.x. Use + * \Drupal\migrate_drupal\Annotation\MigrateField instead. */ -interface MigrateCckFieldInterface extends PluginInspectionInterface { - - /** - * Apply any custom processing to the field migration. - * - * @param \Drupal\migrate\Plugin\MigrationInterface $migration - * The migration entity. - */ - public function processField(MigrationInterface $migration); - - /** - * Apply any custom processing to the field instance migration. - * - * @param \Drupal\migrate\Plugin\MigrationInterface $migration - * The migration entity. - */ - public function processFieldInstance(MigrationInterface $migration); - - /** - * Apply any custom processing to the field widget migration. - * - * @param \Drupal\migrate\Plugin\MigrationInterface $migration - * The migration entity. - */ - public function processFieldWidget(MigrationInterface $migration); - - /** - * Apply any custom processing to the field formatter migration. - * - * @param \Drupal\migrate\Plugin\MigrationInterface $migration - * The migration entity. - */ - public function processFieldFormatter(MigrationInterface $migration); - - /** - * Get a map between D6 formatters and D8 formatters for this field type. - * - * This is used by static::processFieldFormatter() in the base class. - * - * @return array - * The keys are D6 formatters and the values are D8 formatters. - */ - public function getFieldFormatterMap(); - - /** - * Get a map between D6 and D8 widgets for this field type. - * - * @return array - * The keys are D6 field widget types and the values D8 widgets. - */ - public function getFieldWidgetMap(); - - /** - * Apply any custom processing to the cck bundle migrations. - * - * @param \Drupal\migrate\Plugin\MigrationInterface $migration - * The migration entity. - * @param string $field_name - * The field name we're processing the value for. - * @param array $data - * The array of field data from CckFieldValues::fieldData(). - */ - public function processCckFieldValues(MigrationInterface $migration, $field_name, $data); - - /** - * Computes the destination type of a migrated field. - * - * @param \Drupal\migrate\Row $row - * The field being migrated. - * - * @return string - * The destination field type. - */ - public function getFieldType(Row $row); - -} +interface MigrateCckFieldInterface extends MigrateFieldInterface { } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php index 56c7b5badc..b406e890f1 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php @@ -2,54 +2,12 @@ namespace Drupal\migrate_drupal\Plugin; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\migrate\Plugin\MigratePluginManager; -use Drupal\migrate\Plugin\MigrationInterface; - /** - * Plugin manager for migrate cckfield plugins. + * Deprecated: Plugin manager for migrate field plugins. * - * @see \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface - * @see \Drupal\migrate\Annotation\MigrateCckField - * @see plugin_api + * @deprecated in Drupal 8.2.x, to be removed before Drupal 9.0.x. Use + * \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager instead. * * @ingroup migration */ -class MigrateCckFieldPluginManager extends MigratePluginManager implements MigrateCckFieldPluginManagerInterface { - - /** - * The default version of core to use for cck field plugins. - * - * These plugins were initially only built and used for Drupal 6 fields. - * Having been extended for Drupal 7 with a "core" annotation, we fall back to - * Drupal 6 where none exists. - */ - const DEFAULT_CORE_VERSION = 6; - - /** - * {@inheritdoc} - */ - public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) { - $core = static::DEFAULT_CORE_VERSION; - if (!empty($configuration['core'])) { - $core = $configuration['core']; - } - elseif (!empty($migration->getPluginDefinition()['migration_tags'])) { - foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) { - if ($tag == 'Drupal 7') { - $core = 7; - } - } - } - - foreach ($this->getDefinitions() as $plugin_id => $definition) { - if (in_array($core, $definition['core'])) { - if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) { - return $plugin_id; - } - } - } - throw new PluginNotFoundException($field_type); - } - -} +class MigrateCckFieldPluginManager extends MigrateFieldPluginManager implements MigrateCckFieldPluginManagerInterface { } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManagerInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManagerInterface.php index a5371b9dc8..5b2adae349 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManagerInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManagerInterface.php @@ -2,27 +2,10 @@ namespace Drupal\migrate_drupal\Plugin; -use Drupal\migrate\Plugin\MigratePluginManagerInterface; -use Drupal\migrate\Plugin\MigrationInterface; - -interface MigrateCckFieldPluginManagerInterface extends MigratePluginManagerInterface { - - /** - * Get the plugin ID from the field type. - * - * @param string $field_type - * The field type being migrated. - * @param array $configuration - * (optional) An array of configuration relevant to the plugin instance. - * @param \Drupal\migrate\Plugin\MigrationInterface|null $migration - * (optional) The current migration instance. - * - * @return string - * The ID of the plugin for the field_type if available. - * - * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException - * If the plugin cannot be determined, such as if the field type is invalid. - */ - public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL); - -} +/** + * Provides an interface for cck field plugin manager. + * + * @deprecated in Drupal 8.2.x, to be removed before Drupal 9.0.x. Use + * \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface instead. + */ +interface MigrateCckFieldPluginManagerInterface extends MigrateFieldPluginManagerInterface { } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php new file mode 100644 index 0000000000..c8cecad333 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php @@ -0,0 +1,87 @@ +getPluginDefinition()['migration_tags'])) { + foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) { + if ($tag == 'Drupal 7') { + $core = 7; + } + } + } + + foreach ($this->getDefinitions() as $plugin_id => $definition) { + if (in_array($core, $definition['core'])) { + if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) { + return $plugin_id; + } + } + } + throw new PluginNotFoundException($field_type); + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManagerInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManagerInterface.php new file mode 100644 index 0000000000..7219c2b301 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManagerInterface.php @@ -0,0 +1,28 @@ +cckPluginManager = $cck_manager; - } +class CckMigration extends FieldMigration { /** * {@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.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} - */ - public function getProcess() { - if (!$this->init) { - $this->init = TRUE; - $source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin(); - if ($source_plugin instanceof RequirementsInterface) { - try { - $source_plugin->checkRequirements(); - } - catch (RequirementsException $e) { - // Kill the rest of the method. - $source_plugin = []; - } - } - foreach ($source_plugin as $row) { - $field_type = $row->getSourceProperty('type'); - try { - $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this); - } - catch (PluginNotFoundException $ex) { - continue; - } - - if (!isset($this->processedFieldTypes[$field_type])) { - $this->processedFieldTypes[$field_type] = TRUE; - // Allow the cckfield plugin to alter the migration as necessary so - // that it knows how to handle fields of this type. - if (!isset($this->cckPluginCache[$field_type])) { - $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, [], $this); - } - call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this); - } - } - } - return parent::getProcess(); - } + const PLUGIN_METHOD = 'cck_plugin_method'; } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php b/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php new file mode 100644 index 0000000000..62976db8bb --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/FieldMigration.php @@ -0,0 +1,144 @@ +fieldPluginManager = $field_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.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} + */ + public function getProcess() { + if (!$this->init) { + $this->init = TRUE; + $source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin(); + if ($source_plugin instanceof RequirementsInterface) { + try { + $source_plugin->checkRequirements(); + } + catch (RequirementsException $e) { + // Kill the rest of the method. + $source_plugin = []; + } + } + foreach ($source_plugin as $row) { + $field_type = $row->getSourceProperty('type'); + try { + $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this); + } + catch (PluginNotFoundException $ex) { + continue; + } + + if (!isset($this->processedFieldTypes[$field_type]) && $this->fieldPluginManager->hasDefinition($plugin_id)) { + $this->processedFieldTypes[$field_type] = TRUE; + // Allow the field plugin to alter the migration as necessary so that + // it knows how to handle fields of this type. + if (!isset($this->fieldPluginCache[$field_type])) { + $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, [], $this); + } + $method = $this->pluginDefinition[static::PLUGIN_METHOD]; + call_user_func([$this->fieldPluginCache[$field_type], $method], $this); + } + } + } + return parent::getProcess(); + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php index d942bce2c4..bf9e51d75a 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php @@ -2,82 +2,14 @@ namespace Drupal\migrate_drupal\Plugin\migrate\cckfield; -use Drupal\Core\Plugin\PluginBase; -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface; +use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase; /** - * The base class for all cck field plugins. + * The base class for all field plugins. * - * @see \Drupal\migrate\Plugin\MigratePluginManager - * @see \Drupal\migrate_drupal\Annotation\MigrateCckField - * @see \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface - * @see plugin_api + * @deprecated in Drupal 8.2.x, to be removed before Drupal 9.0.x. Use + * \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead. * * @ingroup migration */ -abstract class CckFieldPluginBase extends PluginBase implements MigrateCckFieldInterface { - - /** - * {@inheritdoc} - */ - public function processField(MigrationInterface $migration) { - $process[0]['map'][$this->pluginId][$this->pluginId] = $this->pluginId; - $migration->mergeProcessOfProperty('type', $process); - } - - /** - * {@inheritdoc} - */ - public function processFieldInstance(MigrationInterface $migration) { - // Nothing to do by default with field instances. - } - - /** - * {@inheritdoc} - */ - public function processFieldWidget(MigrationInterface $migration) { - $process = []; - foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) { - $process['type']['map'][$source_widget] = $destination_widget; - } - $migration->mergeProcessOfProperty('options/type', $process); - } - - /** - * {@inheritdoc} - */ - public function getFieldWidgetMap() { - // By default, use the plugin ID for the widget types. - return [ - $this->pluginId => $this->pluginId . '_default', - ]; - } - - /** - * {@inheritdoc} - */ - public function processFieldFormatter(MigrationInterface $migration) { - $process = []; - foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) { - $process[0]['map'][$this->pluginId][$source_format] = $destination_format; - } - $migration->mergeProcessOfProperty('options/type', $process); - } - - /** - * {@inheritdoc} - */ - public function getFieldType(Row $row) { - $field_type = $row->getSourceProperty('type'); - - if (isset($this->pluginDefinition['type_map'][$field_type])) { - return $this->pluginDefinition['type_map'][$field_type]; - } - else { - return $field_type; - } - } - -} +abstract class CckFieldPluginBase extends FieldPluginBase { } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php new file mode 100644 index 0000000000..852c6ca6ff --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/FieldPluginBase.php @@ -0,0 +1,83 @@ +pluginId][$this->pluginId] = $this->pluginId; + $migration->mergeProcessOfProperty('type', $process); + } + + /** + * {@inheritdoc} + */ + public function processFieldInstance(MigrationInterface $migration) { + // Nothing to do by default with field instances. + } + + /** + * {@inheritdoc} + */ + public function processFieldWidget(MigrationInterface $migration) { + $process = []; + foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) { + $process['type']['map'][$source_widget] = $destination_widget; + } + $migration->mergeProcessOfProperty('options/type', $process); + } + + /** + * {@inheritdoc} + */ + public function getFieldWidgetMap() { + // By default, use the plugin ID for the widget types. + return [ + $this->pluginId => $this->pluginId . '_default', + ]; + } + + /** + * {@inheritdoc} + */ + public function processFieldFormatter(MigrationInterface $migration) { + $process = []; + foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) { + $process[0]['map'][$this->pluginId][$source_format] = $destination_format; + } + $migration->mergeProcessOfProperty('options/type', $process); + } + + /** + * {@inheritdoc} + */ + public function getFieldType(Row $row) { + $field_type = $row->getSourceProperty('type'); + + if (isset($this->pluginDefinition['type_map'][$field_type])) { + return $this->pluginDefinition['type_map'][$field_type]; + } + else { + return $field_type; + } + } + +} diff --git a/core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/migrate_cckfield_plugin_manager_test.info.yml b/core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/migrate_cckfield_plugin_manager_test.info.yml deleted file mode 100644 index 8449e1ade0..0000000000 --- a/core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/migrate_cckfield_plugin_manager_test.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'Migrate cck field plugin manager test' -type: module -description: 'Example module demonstrating the cck field plugin manager in the Migrate API.' -package: Testing -version: VERSION -core: 8.x diff --git a/core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/src/Plugin/migrate/cckfield/D6FileField.php b/core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/src/Plugin/migrate/cckfield/D6FileField.php deleted file mode 100644 index 529907a35f..0000000000 --- a/core/modules/migrate_drupal/tests/modules/migrate_cckfield_plugin_manager_test/src/Plugin/migrate/cckfield/D6FileField.php +++ /dev/null @@ -1,29 +0,0 @@ -container->get('plugin.manager.migrate.field'); $plugin_id = $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 6]); - $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d6\\FileField', get_class($plugin_manager->createInstance($plugin_id, ['core' => 6]))); + $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\field\\d6\\FileField', get_class($plugin_manager->createInstance($plugin_id, ['core' => 6]))); try { // If this test passes, getPluginIdFromFieldType will raise a diff --git a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php index 3fba70ac40..15f82b6982 100644 --- a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php @@ -8,7 +8,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; 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; /** @@ -25,18 +25,18 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { protected $basePluginId; /** - * Already-instantiated cckfield plugins, keyed by ID. + * Already-instantiated field plugins, keyed by ID. * - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[] + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[] */ - protected $cckPluginCache; + protected $fieldPluginCache; /** - * The CCK plugin manager. + * The field plugin manager. * - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface */ - protected $cckPluginManager; + protected $fieldPluginManager; /** * Whether or not to include translations. @@ -50,14 +50,14 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { * * @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. * @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, MigrateFieldPluginManagerInterface $field_manager, $translations) { $this->basePluginId = $base_plugin_id; - $this->cckPluginManager = $cck_manager; + $this->fieldPluginManager = $field_manager; $this->includeTranslations = $translations; } @@ -68,7 +68,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) { // Translations don't make sense unless we have content_translation. 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 +90,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 +102,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. } @@ -130,12 +130,12 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($fields[$node_type] as $field_name => $info) { $field_type = $info['type']; try { - $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration); - if (!isset($this->cckPluginCache[$field_type])) { - $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 6], $migration); + $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->cckPluginCache[$field_type] - ->processCckFieldValues($migration, $field_name, $info); + $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 bd3d8b9fc3..74c6a81a60 100644 --- a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php @@ -8,7 +8,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; 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; /** @@ -25,30 +25,30 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface { protected $basePluginId; /** - * Already-instantiated cckfield plugins, keyed by ID. + * Already-instantiated field plugins, keyed by ID. * - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[] + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[] */ - protected $cckPluginCache; + protected $fieldPluginCache; /** - * The CCK plugin manager. + * The field plugin manager. * - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface */ - protected $cckPluginManager; + 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, MigrateFieldPluginManagerInterface $field_manager) { $this->basePluginId = $base_plugin_id; - $this->cckPluginManager = $cck_manager; + $this->fieldPluginManager = $field_manager; } /** @@ -57,7 +57,7 @@ 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.field') ); } @@ -100,12 +100,12 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($fields[$node_type] as $field_name => $info) { $field_type = $info['type']; try { - $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration); - if (!isset($this->cckPluginCache[$field_type])) { - $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 7], $migration); + $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->cckPluginCache[$field_type] - ->processCckFieldValues($migration, $field_name, $info); + $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/source/d6/Node.php b/core/modules/node/src/Plugin/migrate/source/d6/Node.php index 86864156cb..4fcc191702 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php @@ -134,24 +134,24 @@ public function prepareRow(Row $row) { } /** - * Gets CCK field values for a node. + * Gets field values for a node. * * @param \Drupal\migrate\Row $node * The node. * * @return array - * CCK field values, keyed by field name. + * Field values, keyed by field name. */ protected function getFieldValues(Row $node) { $values = []; foreach ($this->getFieldInfo($node->getSourceProperty('type')) as $field => $info) { - $values[$field] = $this->getCckData($info, $node); + $values[$field] = $this->getFieldData($info, $node); } return $values; } /** - * Gets CCK field and instance definitions from the database. + * Gets field and instance definitions from the database. * * @param string $node_type * The node type for which to get field info. @@ -163,7 +163,7 @@ protected function getFieldInfo($node_type) { if (!isset($this->fieldInfo)) { $this->fieldInfo = []; - // Query the database directly for all CCK field info. + // Query the database directly for all field info. $query = $this->select('content_node_field_instance', 'cnfi'); $query->join('content_node_field', 'cnf', 'cnf.field_name = cnfi.field_name'); $query->fields('cnfi'); @@ -188,7 +188,7 @@ protected function getFieldInfo($node_type) { } /** - * Retrieves raw CCK field data for a node. + * Retrieves raw field data for a node. * * @param array $field * A field and instance definition from getFieldInfo(). @@ -198,7 +198,7 @@ protected function getFieldInfo($node_type) { * @return array * The field values, keyed by delta. */ - protected function getCckData(array $field, Row $node) { + protected function getFieldData(array $field, Row $node) { $field_table = 'content_' . $field['field_name']; $node_table = 'content_type_' . $node->getSourceProperty('type'); @@ -234,10 +234,9 @@ protected function getCckData(array $field, Row $node) { return $query // This call to isNotNull() is a kludge which relies on the convention - // that CCK field schemas usually define their most important - // column first. A better way would be to allow cckfield plugins to - // alter the query directly before it's run, but this will do for - // the time being. + // that field schemas usually define their most important column first. + // A better way would be to allow field plugins to alter the query + // directly before it's run, but this will do for the time being. ->isNotNull($field['field_name'] . '_' . $columns[0]) ->condition('nid', $node->getSourceProperty('nid')) ->condition('vid', $node->getSourceProperty('vid')) @@ -249,6 +248,24 @@ protected function getCckData(array $field, Row $node) { } } + /** + * Retrieves raw field data for a node. + * + * @deprecated in Drupal 8.2.x, to be removed in Drupal 9.0.x. Use + * getFieldData() instead. + * + * @param array $field + * A field and instance definition from getFieldInfo(). + * @param \Drupal\migrate\Row $node + * The node. + * + * @return array + * The field values, keyed by delta. + */ + protected function getCckData(array $field, Row $node) { + return $this->getFieldData($field, $node); + } + /** * {@inheritdoc} */ diff --git a/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php b/core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php similarity index 65% rename from core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php rename to core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php index c3035c4312..da72ee792c 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/cckfield/TaxonomyTermReference.php +++ b/core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php @@ -1,12 +1,12 @@ 'iterator', 'source' => $field_name, diff --git a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php b/core/modules/text/src/Plugin/migrate/field/TextField.php similarity index 91% rename from core/modules/text/src/Plugin/migrate/cckfield/TextField.php rename to core/modules/text/src/Plugin/migrate/field/TextField.php index 89475ffd22..c1bf0e48ae 100644 --- a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php +++ b/core/modules/text/src/Plugin/migrate/field/TextField.php @@ -1,13 +1,13 @@ [ diff --git a/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php b/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php index 323fbce8cb..42cf892d8a 100644 --- a/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php +++ b/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php @@ -5,17 +5,17 @@ use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Drupal\Tests\UnitTestCase; -use Drupal\text\Plugin\migrate\cckfield\TextField; +use Drupal\text\Plugin\migrate\field\TextField; use Prophecy\Argument; /** - * @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField + * @coversDefaultClass \Drupal\text\Plugin\migrate\field\TextField * @group text */ class TextFieldTest extends UnitTestCase { /** - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface */ protected $plugin; @@ -32,7 +32,7 @@ protected function setUp() { $migration = $this->prophesize(MigrationInterface::class); - // The plugin's processCckFieldValues() method will call + // The plugin's processFieldValues() method will call // setProcessOfProperty() and return nothing. So, in order to examine the // process pipeline created by the plugin, we need to ensure that // getProcess() always returns the last input to setProcessOfProperty(). @@ -45,13 +45,13 @@ protected function setUp() { } /** - * @covers ::processCckFieldValues + * @covers ::processFieldValues */ public function testProcessFilteredTextFieldValues() { $field_info = [ 'widget_type' => 'text_textfield', ]; - $this->plugin->processCckFieldValues($this->migration, 'body', $field_info); + $this->plugin->processFieldValues($this->migration, 'body', $field_info); $process = $this->migration->getProcess(); $this->assertSame('iterator', $process['plugin']); @@ -68,7 +68,7 @@ public function testProcessFilteredTextFieldValues() { } /** - * @covers ::processCckFieldValues + * @covers ::processFieldValues */ public function testProcessBooleanTextImplicitValues() { $info = array( @@ -77,7 +77,7 @@ public function testProcessBooleanTextImplicitValues() { 'allowed_values' => "foo\nbar", ) ); - $this->plugin->processCckFieldValues($this->migration, 'field', $info); + $this->plugin->processFieldValues($this->migration, 'field', $info); $expected = [ 'value' => [ @@ -93,7 +93,7 @@ public function testProcessBooleanTextImplicitValues() { } /** - * @covers ::processCckFieldValues + * @covers ::processFieldValues */ public function testProcessBooleanTextExplicitValues() { $info = array( @@ -102,7 +102,7 @@ public function testProcessBooleanTextExplicitValues() { 'allowed_values' => "foo|Foo\nbaz|Baz", ) ); - $this->plugin->processCckFieldValues($this->migration, 'field', $info); + $this->plugin->processFieldValues($this->migration, 'field', $info); $expected = [ 'value' => [ diff --git a/core/modules/user/src/Plugin/migrate/User.php b/core/modules/user/src/Plugin/migrate/User.php index 986b58d2fd..b8d804ea06 100644 --- a/core/modules/user/src/Plugin/migrate/User.php +++ b/core/modules/user/src/Plugin/migrate/User.php @@ -11,7 +11,7 @@ class User extends Migration { /** - * Flag indicating whether the CCK data has been filled already. + * Flag indicating whether the field data has been filled already. * * @var bool */ -- GitLab