diff --git a/core/modules/field/migration_templates/d6_field.yml b/core/modules/field/migration_templates/d6_field.yml index 531bc132d1ef23707f320d14bc678a68eb24342c..4f68e42848c7f0f4523f26e3380a2eee4560e889 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 7496db3931741a06ff46cda538421a45e964d432..5140f21e5de022e31c4267b6381b4ef24205889f 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 b5035c2a579b51a50b363a9c122a3b40ae20953a..726e4663d164f92d9291a800d55d586b531b76ca 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 46b7d75989b2fde0cddc93f927f6cb2192f3dac7..984872dd1ad39d4020b289bd7aac8721df46aba0 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 18135affbb5410392eafcca01ffd5f9ac0896741..8836502c226c6c89883e463a03dc6bb971312cd7 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 ee07ec4be06f79cb07373fd23c576685b53d5cc6..f82d92d95a03e12c4a6fa2c1e13b880399156666 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 b6d2497e534897a7ef25640be5e5b698aeb36ea2..4996af623b69d44ed23f3e813afba206249d671d 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 f88f2d2057c9731d8985092fedbdef26fc598a69..362634649630ccbc757c3de3d62014726735277a 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 7874f9c3b7aae49c9b60451bb9fed0fe1ccc61fa..27ccb526fbae6c4e06ef3461ec95ff36916008ee 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 d63b9c2901b7fa2e1e2185c42f5674ba25e207a4..930c13b030020ca6005cd27a42ff915e4a812c40 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 d0b1335e8030afd45c290df33458ee8ad41acff3..8430c8b8b0eb99f7a8f8087a07c047f19c4a8494 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 7f47caa96e0b109bc7967df1ba7f3dd6131c324f..f63cde2bae2456fa641ec89b918953f79d9062ee 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 fd2f42c3f9819594175bd783fd3eaa2fbd101eb4..15198512598629964f7167303e1ceac6337c400f 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 0000000000000000000000000000000000000000..165b47c91a103ce662b2410baf28468e5a339969 --- /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 1ee73a83eee735cfea0d3fbdb231c2daf56e3ed9..c807b4fbdd7e304951fb0afbcd28dd9c288ab9e9 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 314e8df8a6e7c6f34ecaf85a779ed713bc691f62..0a506bf2bb8de8a43dd4af5ad45f8502cf00d030 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 3d657baa5b469537d9f80b942bc2062705c8a135..64a10ba733b830dd47b43787b42f75590124fea4 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 0000000000000000000000000000000000000000..4badcb6c66e5eda3c9e2eeba917d5b72e4431f16 --- /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 a96287aebabb62d9340c6618ad4248c2c848495c..4b4eda2249871fb6fc0310d7ed721e8f0765af5b 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 71a0b277827e184a7ffe8860d2f26bbaf2c093cd..d22788f81a239da59b0d591f41d65f584e4d5c33 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 5e5a5004674c39d2bcec7265fd90efe04ae49cd5..39edf3e7ea2fdf17ed3a67d4dbb9d854c1d1f8ad 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 0000000000000000000000000000000000000000..ad78bc924d5f7220885d6db9d771bf58041fa72c --- /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 b30b2b81c3f6bdc83d1a3e89b010fdddf69a8a9d..6d270b78701fd75283cad2140a0563ba2f4cc676 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 56c7b5badc6c8fa9c063f06284699aaa0a1f1ce5..b406e890f1725a423d51aa6594f16bdb1188452f 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 a5371b9dc85ef12ab54b2c4aac6c84b5b85c3888..5b2adae34944f4557e8c4dce1ba2b7e140ac6c17 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 0000000000000000000000000000000000000000..c8cecad3338c6b75fdab23e0324274a6587aea2b --- /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 0000000000000000000000000000000000000000..7219c2b301e52975cbab76f30939ae30431c4b6c --- /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 0000000000000000000000000000000000000000..62976db8bb09b1bbe3f17f102ba4fb5225be07b1 --- /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 d942bce2c45306d8f627c926072e5f8bd9499dd9..bf9e51d75ab58302234e60289374888a87ce0ac5 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 0000000000000000000000000000000000000000..852c6ca6ff4b9de942827f41743be0951aac4346 --- /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 8449e1ade0e5a79b7f397fdccc26358a74c49e0d..0000000000000000000000000000000000000000 --- 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 529907a35f0e8c883ba02e42800a108098ca5f60..0000000000000000000000000000000000000000 --- 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 3fba70ac407bddc2e8bbe9e0bbd2a6f040e79bbc..15f82b6982566d5a2748f4a3c9d9cef6925b3373 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 bd3d8b9fc3e892c51d41bb2804a6bb2108fe2bb4..74c6a81a60e76fa493ef8b0948fe5b43738daded 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 86864156cbaea1e499aa9f3a7e7876add23aac18..4fcc1917020e536e5d866570d10529e7b312b4fa 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 c3035c4312e03b0f7eab6ac6e2106d5c03a0d551..da72ee792c2a361a6d6caff6690135e2632409ce 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 89475ffd220bf01b12d9692594555edb00d96a13..c1bf0e48ae82f507776d4289a38b677290aa46bd 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 323fbce8cb98a1494afefac7b349dda992123f1b..42cf892d8aed495aa61a4c2b6f641d2b7a18c330 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 986b58d2fdffa2ff5e1f7825b1d204757d711a6f..b8d804ea068ccdadc03610cae23f0ed7ca044271 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 */