diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php index 638f705..3164ce7 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php @@ -22,7 +22,7 @@ class FieldInstanceSettings extends ProcessPluginBase implements ContainerFactor * * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $cckPluginManager; + protected $fieldPluginManager; /** * Constructs a FieldSettings plugin. @@ -33,12 +33,12 @@ class FieldInstanceSettings extends ProcessPluginBase implements ContainerFactor * The plugin ID. * @param mixed $plugin_definition * The plugin definition. - * @param \Drupal\Component\Plugin\PluginManagerInterface $cck_plugin_manager - * The cckfield plugin manager. + * @param \Drupal\Component\Plugin\PluginManagerInterface $field_plugin_manager + * The field plugin manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $cck_plugin_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $field_plugin_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->cckPluginManager = $cck_plugin_manager; + $this->fieldPluginManager = $field_plugin_manager; } /** @@ -49,7 +49,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') ); } @@ -60,7 +60,7 @@ public static function create(ContainerInterface $container, array $configuratio */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { try { - return $this->cckPluginManager->createInstance($row->getSourceProperty('type'), ['core' => 6]) + return $this->fieldPluginManager->createInstance($row->getSourceProperty('type'), ['core' => 6]) ->transformFieldInstanceSettings($row); } catch (PluginNotFoundException $e) { diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php index fa19665..87e9ea2 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php @@ -24,7 +24,7 @@ class FieldSettings extends ProcessPluginBase implements ContainerFactoryPluginI * * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $cckPluginManager; + protected $fieldPluginManager; /** * Constructs a FieldSettings plugin. @@ -35,12 +35,12 @@ class FieldSettings extends ProcessPluginBase implements ContainerFactoryPluginI * The plugin ID. * @param mixed $plugin_definition * The plugin definition. - * @param \Drupal\Component\Plugin\PluginManagerInterface $cck_plugin_manager - * The cckfield plugin manager. + * @param \Drupal\Component\Plugin\PluginManagerInterface $field_plugin_manager + * The field plugin manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $cck_plugin_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $field_plugin_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->cckPluginManager = $cck_plugin_manager; + $this->fieldPluginManager = $field_plugin_manager; } /** @@ -51,7 +51,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') ); } @@ -69,7 +69,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable list($field_type, $global_settings, $source_field_type) = $value; try { - return $this->cckPluginManager->createInstance($source_field_type, ['core' => 6]) + return $this->fieldPluginManager->createInstance($source_field_type, ['core' => 6]) ->transformFieldStorageSettings($row); } catch (PluginNotFoundException $e) { diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldWidgetType.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldWidgetType.php index 0dbbbba..0607778 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldWidgetType.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldWidgetType.php @@ -24,7 +24,7 @@ class FieldWidgetType extends ProcessPluginBase implements ContainerFactoryPlugi * * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $cckPluginManager; + protected $fieldPluginManager; /** * Constructs a FieldSettings plugin. @@ -35,12 +35,12 @@ class FieldWidgetType extends ProcessPluginBase implements ContainerFactoryPlugi * The plugin ID. * @param mixed $plugin_definition * The plugin definition. - * @param \Drupal\Component\Plugin\PluginManagerInterface $cck_plugin_manager - * The cckfield plugin manager. + * @param \Drupal\Component\Plugin\PluginManagerInterface $field_plugin_manager + * The field plugin manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $cck_plugin_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $field_plugin_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->cckPluginManager = $cck_plugin_manager; + $this->fieldPluginManager = $field_plugin_manager; } /** @@ -51,7 +51,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') ); } @@ -63,7 +63,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $source_field_type = $row->getSourceProperty('type'); try { - return $this->cckPluginManager->createInstance($source_field_type, ['core' => 6]) + return $this->fieldPluginManager->createInstance($source_field_type, ['core' => 6]) ->transformWidgetType($row); } catch (PluginNotFoundException $e) { diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php index 41ce3b2..c2beda0 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php @@ -104,23 +104,23 @@ public function testFieldInstanceMigration() { // Test node reference to entity reference migration. $field = FieldConfig::load('node.story.field_node_reference'); - $this->assertIdentical('Node reference', $field->label()); - $this->assertIdentical('default:node', $field->getSetting('handler')); + $this->assertSame('Node reference', $field->label()); + $this->assertSame('default:node', $field->getSetting('handler')); $expected = [ 'target_bundles' => [] ]; - $this->assertIdentical($expected, $field->getSetting('handler_settings')); + $this->assertSame($expected, $field->getSetting('handler_settings')); // Test node reference to entity reference migration. $field = FieldConfig::load('node.story.field_node_reference_2'); - $this->assertIdentical('Node reference 2', $field->label()); - $this->assertIdentical('default:node', $field->getSetting('handler')); + $this->assertSame('Node reference 2', $field->label()); + $this->assertSame('default:node', $field->getSetting('handler')); $expected = [ 'target_bundles' => [ 'article' => 'article', ], ]; - $this->assertIdentical($expected, $field->getSetting('handler_settings')); + $this->assertSame($expected, $field->getSetting('handler_settings')); // Test user reference to entity reference migration. $field = FieldConfig::load('node.story.field_user_reference'); @@ -133,12 +133,12 @@ public function testFieldInstanceMigration() { ], 'target_bundles' => NULL, ]; - $this->assertIdentical($expected, $field->getSetting('handler_settings')); + $this->assertSame($expected, $field->getSetting('handler_settings')); // Test user reference to entity reference migration. $field = FieldConfig::load('node.story.field_user_reference_2'); - $this->assertIdentical('User reference 2', $field->label()); - $this->assertIdentical('default:user', $field->getSetting('handler')); + $this->assertSame('User reference 2', $field->label()); + $this->assertSame('default:user', $field->getSetting('handler')); $expected = [ 'include_anonymous' => FALSE, 'filter' => [ @@ -149,7 +149,7 @@ public function testFieldInstanceMigration() { ], 'target_bundles' => NULL, ]; - $this->assertIdentical($expected, $field->getSetting('handler_settings')); + $this->assertSame($expected, $field->getSetting('handler_settings')); // Test date field. $field = FieldConfig::load('node.story.field_test_date'); @@ -195,7 +195,7 @@ public function testFieldInstanceMigration() { $this->assertSame('entity_reference', $field->getType()); $this->assertSame('Company', $field->label()); $this->assertSame('default:node', $field->getSetting('handler')); - $this->assertSame([], $field->getSetting('handler_settings')); + $this->assertSame(['target_bundles' => ['company' => 'company']], $field->getSetting('handler_settings')); $this->assertSame('node', $field->getSetting('target_type')); $this->assertSame([], $field->getDefaultValueLiteral()); $this->assertTrue($field->isTranslatable()); @@ -206,7 +206,15 @@ public function testFieldInstanceMigration() { $this->assertSame('entity_reference', $field->getType()); $this->assertSame('Commanding Officer', $field->label()); $this->assertSame('default:user', $field->getSetting('handler')); - $this->assertSame([], $field->getSetting('handler_settings')); + $expected = [ + 'include_anonymous' => FALSE, + 'filter' => [ + 'type' => 'role', + 'role' => ['authenticated' => 'authenticated',], + ], + 'target_bundles' => NULL, + ]; + $this->assertSame($expected, $field->getSetting('handler_settings')); $this->assertSame('user', $field->getSetting('target_type')); $this->assertSame([], $field->getDefaultValueLiteral()); $this->assertTrue($field->isTranslatable()); diff --git a/core/modules/file/src/Plugin/migrate/field/d6/FileField.php b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php index 930c13b..57ee74d 100644 --- a/core/modules/file/src/Plugin/migrate/field/d6/FileField.php +++ b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php @@ -55,4 +55,59 @@ public function getFieldType(Row $row) { return $row->getSourceProperty('widget_type') == 'imagefield_widget' ? 'image' : 'file'; } + /** + * {@inheritdoc} + */ + public function transformFieldInstanceSettings(Row $row) { + $widget_type = $row->getSourceProperty('widget_type'); + $widget_settings = $row->getSourceProperty('widget_settings'); + $field_settings = $row->getSourceProperty('global_settings'); + $settings = []; + + switch ($widget_type) { + case 'filefield_widget': + $settings['file_extensions'] = $widget_settings['file_extensions']; + $settings['file_directory'] = $widget_settings['file_path']; + $settings['description_field'] = $field_settings['description_field']; + $settings['max_filesize'] = $this->convertSizeUnit($widget_settings['max_filesize_per_file']); + break; + + case 'imagefield_widget': + $settings['file_extensions'] = $widget_settings['file_extensions']; + $settings['file_directory'] = $widget_settings['file_path']; + $settings['max_filesize'] = $this->convertSizeUnit($widget_settings['max_filesize_per_file']); + $settings['alt_field'] = $widget_settings['alt']; + $settings['alt_field_required'] = $widget_settings['custom_alt']; + $settings['title_field'] = $widget_settings['title']; + $settings['title_field_required'] = $widget_settings['custom_title']; + // With nothing entered for min or max resolution in Drupal 6, zero is + // stored. For Drupal 8 this should be an empty string. + $settings['max_resolution'] = !empty($widget_settings['max_resolution']) ? $widget_settings['max_resolution'] : ''; + $settings['min_resolution'] = !empty($widget_settings['min_resolution']) ? $widget_settings['min_resolution'] : ''; + break; + } + + return $settings; + } + + /** + * Convert file size strings into their D8 format. + * + * D6 stores file size using a "K" for kilobytes and "M" for megabytes where + * as D8 uses "KB" and "MB" respectively. + * + * @param string $size_string + * The size string, e.g. 10M + * + * @return string + * The D8 version of the size string. + */ + protected function convertSizeUnit($size_string) { + $size_unit = substr($size_string, strlen($size_string) - 1); + if ($size_unit == "M" || $size_unit == "K") { + return $size_string . "B"; + } + return $size_string; + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php index 1579afa..53ce65e 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php @@ -3,6 +3,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\field; use Drupal\migrate\Plugin\MigrationInterface; +use Drupal\migrate\Row; /** * @MigrateField( @@ -13,7 +14,40 @@ * }, * ) */ -class NodeReference extends FieldPluginBase { +class NodeReference extends ReferenceBase { + + /** + * The plugin ID for the node type migration. + * + * @var string + */ + protected $nodeTypeMigration = 'd6_node_type'; + + /** + * {@inheritdoc} + */ + protected function entityId() { + return 'nid'; + } + + /** + * {@inheritdoc} + */ + public function transformFieldStorageSettings(Row $row) { + $settings['target_type'] = 'node'; + return $settings; + } + + /** + * {@inheritdoc} + */ + public function processFieldInstance(MigrationInterface $migration) { + parent::processFieldInstance($migration); + + $migration_dependencies = $migration->get('migration_dependencies'); + $migration_dependencies['required'][] = $this->nodeTypeMigration; + $migration->set('migration_dependencies', $migration_dependencies); + } /** * {@inheritdoc} @@ -33,4 +67,21 @@ public function processFieldValues(MigrationInterface $migration, $field_name, $ $migration->setProcessOfProperty($field_name, $process); } + /** + * {@inheritdoc} + */ + public function transformFieldInstanceSettings(Row $row) { + $source_settings = $row->getSourceProperty('global_settings'); + $settings['handler'] = 'default:node'; + $settings['handler_settings']['target_bundles'] = []; + + if (isset($source_settings['referenceable_types'])) { + $node_types = array_filter($source_settings['referenceable_types']); + if (!empty($node_types)) { + $settings['handler_settings']['target_bundles'] = $this->lookupMigrations($this->nodeTypeMigration, $node_types); + } + } + return $settings; + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php index 14b5152..9ad816a 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php @@ -1,6 +1,6 @@ pluginId . '_select' => 'options_select', + $this->pluginId . '_buttons' => 'options_buttons', + $this->pluginId . '_autocomplete' => 'entity_reference_autocomplete', + ]; + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php index 11df8ec..2e0c40e 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php @@ -3,6 +3,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\field; use Drupal\migrate\Plugin\MigrationInterface; +use Drupal\migrate\Row; /** * @MigrateField( @@ -13,7 +14,40 @@ * }, * ) */ -class UserReference extends FieldPluginBase { +class UserReference extends ReferenceBase { + + /** + * The plugin ID for the user role migration. + * + * @var string + */ + protected $userRoleMigration = 'd6_user_role'; + + /** + * {@inheritdoc} + */ + protected function entityId() { + return 'uid'; + } + + /** + * {@inheritdoc} + */ + public function transformFieldStorageSettings(Row $row) { + $settings['target_type'] = 'user'; + return $settings; + } + + /** + * {@inheritdoc} + */ + public function processFieldInstance(MigrationInterface $migration) { + parent::processFieldInstance($migration); + + $migration_dependencies = $migration->get('migration_dependencies'); + $migration_dependencies['required'][] = $this->userRoleMigration; + $migration->set('migration_dependencies', $migration_dependencies); + } /** * {@inheritdoc} @@ -33,4 +67,25 @@ public function processFieldValues(MigrationInterface $migration, $field_name, $ $migration->setProcessOfProperty($field_name, $process); } + /** + * {@inheritdoc} + */ + public function transformFieldInstanceSettings(Row $row) { + $source_settings = $row->getSourceProperty('global_settings'); + $settings['handler'] = 'default:user'; + $settings['handler_settings']['include_anonymous'] = FALSE; + $settings['handler_settings']['filter']['type'] = '_none'; + $settings['handler_settings']['target_bundles'] = NULL; + + if (isset($source_settings['referenceable_roles'])) { + $roles = array_filter($source_settings['referenceable_roles']); + if (!empty($roles)) { + $settings['handler_settings']['filter']['type'] = 'role'; + $settings['handler_settings']['filter']['role'] = $this->lookupMigrations($this->userRoleMigration, $roles); + } + } + + return $settings; + } + } diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php index 313484e..1144f94 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php @@ -78,8 +78,6 @@ protected function migrateFields() { $this->executeMigrations([ 'd6_filter_format', 'd6_user_role', - ]); - $this->executeMigrations([ 'd6_field', 'd6_field_instance', 'd6_field_instance_widget_settings', diff --git a/core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php b/core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php index 56ec20a..b549f8a 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php +++ b/core/modules/taxonomy/src/Plugin/migrate/field/TaxonomyTermReference.php @@ -2,8 +2,9 @@ namespace Drupal\taxonomy\Plugin\migrate\field; +use Drupal\migrate_drupal\Plugin\migrate\field\ReferenceBase; use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase; +use Drupal\migrate\Row; /** * @MigrateField( @@ -14,7 +15,22 @@ * core = {6,7} * ) */ -class TaxonomyTermReference extends FieldPluginBase { +class TaxonomyTermReference extends ReferenceBase { + + /** + * {@inheritdoc} + */ + protected function entityId() { + return 'tid'; + } + + /** + * {@inheritdoc} + */ + public function transformFieldStorageSettings(Row $row) { + $settings['target_type'] = 'taxonomy_term'; + return $settings; + } /** * {@inheritdoc}