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 3164ce7..467a420 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php @@ -18,7 +18,7 @@ class FieldInstanceSettings extends ProcessPluginBase implements ContainerFactoryPluginInterface { /** - * The cckfield plugin manager. + * The field plugin manager. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ 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 87e9ea2..14ee72b 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php @@ -20,7 +20,7 @@ class FieldSettings extends ProcessPluginBase implements ContainerFactoryPluginInterface { /** - * The cckfield plugin manager. + * The field plugin manager. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ @@ -64,16 +64,13 @@ public function transform($value, MigrateExecutableInterface $migrate_executable if (count($value) == 2) { $value[] = NULL; } - // list($field_type, $global_settings, $original_field_type) = $value; - // return $this->getSettings($field_type, $global_settings, $original_field_type); - list($field_type, $global_settings, $source_field_type) = $value; - + list($field_type, $global_settings, $original_field_type) = $value; try { - return $this->fieldPluginManager->createInstance($source_field_type, ['core' => 6]) + return $this->fieldPluginManager->createInstance($original_field_type, ['core' => 6]) ->transformFieldStorageSettings($row); } catch (PluginNotFoundException $e) { - return $this->getSettings($field_type, $global_settings, $source_field_type); + return $this->getSettings($field_type, $global_settings, $original_field_type); } } 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 0607778..d927af1 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldWidgetType.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldWidgetType.php @@ -20,7 +20,7 @@ class FieldWidgetType extends ProcessPluginBase implements ContainerFactoryPluginInterface { /** - * The cckfield plugin manager. + * The field plugin manager. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ diff --git a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php index aa0b726..86039ff 100644 --- a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php +++ b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php @@ -21,14 +21,14 @@ class FieldSettingsTest extends UnitTestCase { * @dataProvider getSettingsProvider */ public function testGetSettings($field_type, $field_settings, $source_field_type, $allowed_values) { - $cck_plugin_manager = $this->getMockBuilder(MigratePluginManager::class) + $plugin_manager = $this->getMockBuilder(MigratePluginManager::class) ->disableOriginalConstructor() ->getMock(); - $cck_plugin_manager->method('createInstance') + $plugin_manager->method('createInstance') ->willThrowException(new PluginNotFoundException($source_field_type)); - $plugin = new FieldSettings([], 'd6_field_settings', [], $cck_plugin_manager); + $plugin = new FieldSettings([], 'd6_field_settings', [], $plugin_manager); $executable = $this->getMock(MigrateExecutableInterface::class); $row = $this->getMockBuilder(Row::class) diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php index 1c74d5a..8dba3b0 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php @@ -64,60 +64,4 @@ 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/file/src/Plugin/migrate/cckfield/d7/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php index c156f25..3a4cf89 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php @@ -69,57 +69,4 @@ 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'] = 'public://'; - $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']; - $settings['max_resolution'] = $widget_settings['max_resolution']; - $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/file/src/Plugin/migrate/field/d7/FileField.php b/core/modules/file/src/Plugin/migrate/field/d7/FileField.php index 2d7e7ba..611605e 100644 --- a/core/modules/file/src/Plugin/migrate/field/d7/FileField.php +++ b/core/modules/file/src/Plugin/migrate/field/d7/FileField.php @@ -4,6 +4,7 @@ use Drupal\file\Plugin\migrate\field\d6\FileField as D6FileField; use Drupal\migrate\Plugin\MigrationInterface; +use Drupal\migrate\Row; /** * @MigrateField( @@ -31,4 +32,37 @@ public function processFieldValues(MigrationInterface $migration, $field_name, $ $migration->mergeProcessOfProperty($field_name, $process); } + /** + * {@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'] = 'public://'; + $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']; + $settings['max_resolution'] = $widget_settings['max_resolution']; + $settings['min_resolution'] = $widget_settings['min_resolution']; + break; + } + + return $settings; + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php index 6f9eba1..6dceeab 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php @@ -28,32 +28,4 @@ */ public function processCckFieldValues(MigrationInterface $migration, $field_name, $data); - /** - * Apply any custom transformation to the field storage settings. - * - * @param \Drupal\migrate\Row $row - * The field being migrated. - * - * @return array - * The destination storage settings. - * - * @see Drupal\field\Plugin\migrate\process\d6\FieldSettings::transform - * @see Drupal\migrate\Plugin\MigrateProcessInterface::transform - */ - public function transformFieldStorageSettings(Row $row); - - /** - * Apply any custom transformation to the field instance settings. - * - * @param \Drupal\migrate\Row $row - * The field being migrated. - * - * @return array - * The destination instance settings. - * - * @see Drupal\field\Plugin\migrate\process\d6\FieldInstanceSettings::transform - * @see Drupal\migrate\Plugin\MigrateProcessInterface::transform - */ - public function transformFieldInstanceSettings(Row $row); - } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php index 2aac5d1..0bb30f7 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldInterface.php @@ -106,4 +106,32 @@ public function processFieldValues(MigrationInterface $migration, $field_name, $ */ public function getFieldType(Row $row); + /** + * Apply any custom transformation to the field storage settings. + * + * @param \Drupal\migrate\Row $row + * The field being migrated. + * + * @return array + * The destination storage settings. + * + * @see \Drupal\field\Plugin\migrate\process\d6\FieldSettings::transform + * @see \Drupal\migrate\Plugin\MigrateProcessInterface::transform + */ + public function transformFieldStorageSettings(Row $row); + + /** + * Apply any custom transformation to the field instance settings. + * + * @param \Drupal\migrate\Row $row + * The field being migrated. + * + * @return array + * The destination instance settings. + * + * @see \Drupal\field\Plugin\migrate\process\d6\FieldInstanceSettings::transform + * @see \Drupal\migrate\Plugin\MigrateProcessInterface::transform + */ + public function transformFieldInstanceSettings(Row $row); + } 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 4880f53..db7812d 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php @@ -69,9 +69,9 @@ public function getFieldFormatterMap() { /** * {@inheritdoc} */ - public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { + public function processFieldValues(MigrationInterface $migration, $field_name, $data) { $process = [ - 'plugin' => 'iterator', + 'plugin' => 'sub_process', 'source' => $field_name, 'process' => ['target_id' => $this->entityId()], ]; diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index 7b19cae..a45e223 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -2364,7 +2364,7 @@ 'vid' => '1', 'nid' => '1', 'delta' => '0', - 'field_node_reference_nid' => 2, + 'field_node_reference_nid' => NULL, )) ->values(array( 'vid' => '2', @@ -2376,7 +2376,7 @@ 'vid' => '3', 'nid' => '2', 'delta' => '0', - 'field_node_reference_nid' => NULL, + 'field_node_reference_nid' => 1, )) ->values(array( 'vid' => '5', @@ -2388,7 +2388,7 @@ 'vid' => '12', 'nid' => '9', 'delta' => '0', - 'field_node_reference_nid' => NULL, + 'field_node_reference_nid' => 2, )) ->execute();