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 534501d527..fd54627aac 100644 --- a/core/modules/field/migration_templates/d6_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d6_field_formatter_settings.yml @@ -172,7 +172,7 @@ process: default: entity_reference_label plain: entity_reference_label - - plugin: field_type_defaults + plugin: d6_field_type_defaults "options/settings": - plugin: static_map 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 126fd29a20..407e17bdaf 100644 --- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml @@ -51,19 +51,24 @@ process: - plugin: static_map bypass: true - source: formatter_type + source: + - type + - formatter_type map: - date_default: datetime_default - email_default: email_mailto - # 0 should cause the row to be skipped by the next plugin in the - # pipeline. - hidden: 0 - link_default: link - phone: basic_string - taxonomy_term_reference_link: entity_reference_label - entityreference_label: entity_reference_label - entityreference_entity_id: entity_reference_entity_id - entityreference_entity_view: entity_reference_entity_view + email: + email_default: email_mailto + link_field: + link_default: link + phone: + phone: basic_string + taxonomy_term_reference: + taxonomy_term_reference_link: entity_reference_label + entityreference: + entityreference_label: entity_reference_label + entityreference_entity_id: entity_reference_entity_id + entityreference_entity_view: entity_reference_entity_view + - + plugin: d7_field_type_defaults - plugin: skip_on_empty method: row diff --git a/core/modules/field/src/Plugin/migrate/process/FieldTypeDefaults.php b/core/modules/field/src/Plugin/migrate/process/FieldTypeDefaults.php new file mode 100644 index 0000000000..bf507e5a7a --- /dev/null +++ b/core/modules/field/src/Plugin/migrate/process/FieldTypeDefaults.php @@ -0,0 +1,15 @@ +getSourceProperty('module') == 'date') { + $value = 'datetime_default'; + } + else { + $value = $row->getSourceProperty('formatter_type'); + if ($value == 'hidden') { + $value = 0; + } + } + } + return $value; + } + +} diff --git a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d7/FieldTypeDefaultsTest.php b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d7/FieldTypeDefaultsTest.php new file mode 100644 index 0000000000..350703448d --- /dev/null +++ b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d7/FieldTypeDefaultsTest.php @@ -0,0 +1,75 @@ +plugin = new FieldTypeDefaults([], 'd7_field_type_defaults', []); + } + + /** + * Tests various default cases. + * + * @covers ::transform + */ + public function testDefaults() { + $this->row->expects($this->once()) + ->method('getSourceProperty') + ->willReturn('date'); + + // Assert common values are passed through without modification. + $this->assertNull($this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'property')); + $this->assertEquals('string', $this->plugin->transform('string', $this->migrateExecutable, $this->row, 'property')); + $this->assertEquals(1234, $this->plugin->transform(1234, $this->migrateExecutable, $this->row, 'property')); + // Assert that an array checks that this is a date field(above mock assert) + // and returns "datetime_default". + $this->assertEquals('datetime_default', $this->plugin->transform([], $this->migrateExecutable, $this->row, 'property')); + } + + /** + * Tests hidden formatter. + * + * @covers ::transform + */ + public function testHidden() { + $this->row->expects($this->exactly(2)) + ->method('getSourceProperty') + ->willReturn('hidden'); + + $this->assertEquals(0, $this->plugin->transform(['hidden'], $this->migrateExecutable, $this->row, 'property')); + } + + /** + * Tests return of field_formatter value. + * + * @covers ::transform + */ + public function testFieldFormatter() { + $this->row->expects($this->exactly(2)) + ->method('getSourceProperty') + ->willReturn('foo'); + + // Assert common values are passed through without modification. + $this->assertNull($this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'property')); + $this->assertEquals('string', $this->plugin->transform('string', $this->migrateExecutable, $this->row, 'property')); + $this->assertEquals(1234, $this->plugin->transform(1234, $this->migrateExecutable, $this->row, 'property')); + // Assert that an array that this is not a date field and returns + // the value of the field_formatter property. + $this->assertEquals('foo', $this->plugin->transform(['one', 'two', 'three'], $this->migrateExecutable, $this->row, 'property')); + } + +}