Commit b89d3e4f authored by catch's avatar catch

Issue #2843617 by maxocub, hussainweb, joelpittet, quietone, heddn, Jo...

Issue #2843617 by maxocub, hussainweb, joelpittet, quietone, heddn, Jo Fitzgerald: Field formatter mappings defined in getFieldFormatterMap have no effect
parent d97c58ac
......@@ -32,10 +32,14 @@ public function getFieldWidgetMap() {
*/
public function getFieldFormatterMap() {
return [
'email_formatter_default' => 'basic_string',
'email_formatter_default' => 'email_mailto',
'email_formatter_contact' => 'basic_string',
'email_formatter_plain' => 'basic_string',
'email_formatter_spamspan' => 'basic_string',
'email_default' => 'email_mailto',
'email_contact' => 'basic_string',
'email_plain' => 'basic_string',
'email_spamspan' => 'basic_string',
];
}
......
......@@ -15,4 +15,17 @@
* destination_module = "core"
* )
*/
class EntityReference extends FieldPluginBase {}
class EntityReference extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'entityreference_label' => 'entity_reference_label',
'entityreference_entity_id' => 'entity_reference_entity_id',
'entityreference_entity_view' => 'entity_reference_entity_view',
];
}
}
......@@ -21,6 +21,15 @@
*/
class DateField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'date_default' => 'datetime_default',
];
}
/**
* {@inheritdoc}
*/
......
......@@ -173,7 +173,7 @@ process:
default: entity_reference_label
plain: entity_reference_label
-
plugin: field_type_defaults
plugin: d6_field_type_defaults
"options/settings":
-
plugin: static_map
......
......@@ -55,6 +55,11 @@ process:
field_name: field_name
"options/label": 'formatter/label'
"options/weight": 'formatter/weight'
# The field plugin ID.
plugin_id:
plugin: process_field
source: type
method: getPluginId
# The formatter to use.
formatter_type:
plugin: process_field
......@@ -64,19 +69,14 @@ process:
-
plugin: static_map
bypass: true
source: '@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
source:
- '@plugin_id'
- '@formatter_type'
# The map is generated by the getFieldFormatterMap() method from the
# migrate field plugins.
map: []
-
plugin: d7_field_type_defaults
-
plugin: skip_on_empty
method: row
......
<?php
namespace Drupal\field\Plugin\migrate\process;
@trigger_error('The field_type_defaults process plugin is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use d6_field_type_defaults or d7_field_type_defaults instead. See https://www.drupal.org/node/2944589.', E_USER_DEPRECATED);
use Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults as D6FieldTypeDefaults;
/**
* BC Layer.
*
* @MigrateProcessPlugin(
* id = "field_type_defaults"
* )
*
* @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.x.
* Use d6_field_type_defaults or d7_field_type_defaults instead.
*
* @see https://www.drupal.org/node/2944589
*/
class FieldTypeDefaults extends D6FieldTypeDefaults {}
......@@ -11,7 +11,7 @@
* Gives us a chance to set per field defaults.
*
* @MigrateProcessPlugin(
* id = "field_type_defaults"
* id = "d6_field_type_defaults"
* )
*/
class FieldTypeDefaults extends ProcessPluginBase {
......
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Gives us a chance to set per field defaults.
*
* @MigrateProcessPlugin(
* id = "d7_field_type_defaults"
* )
*/
class FieldTypeDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value) && isset($value[1])) {
return $value[1];
}
return $value;
}
}
<?php
namespace Drupal\Tests\field\Unit\Plugin\migrate\process;
use Drupal\field\Plugin\migrate\process\FieldTypeDefaults;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests the deprecation of the field_type_defaults process plugin.
*
* @coversDefaultClass \Drupal\field\Plugin\migrate\process\FieldTypeDefaults
* @group field
* @group legacy
*/
class FieldTypeDefaultsTest extends MigrateProcessTestCase {
/**
* Tests that the field_type_defaults plugin triggers a deprecation error.
*
* @expectedDeprecation The field_type_defaults process plugin is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use d6_field_type_defaults or d7_field_type_defaults instead. See https://www.drupal.org/node/2944589.
*/
public function testDeprecatedError() {
$this->plugin = new FieldTypeDefaults([], 'field_type_defaults', []);
}
}
......@@ -19,7 +19,7 @@ class FieldTypeDefaultsTest extends MigrateProcessTestCase {
*/
protected function setUp() {
parent::setUp();
$this->plugin = new FieldTypeDefaults([], 'field_type_defaults', []);
$this->plugin = new FieldTypeDefaults([], 'd6_field_type_defaults', []);
}
/**
......
<?php
namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d7;
use Drupal\field\Plugin\migrate\process\d7\FieldTypeDefaults;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests D7 field formatter defaults.
*
* @coversDefaultClass \Drupal\field\Plugin\migrate\process\d7\FieldTypeDefaults
* @group field
*/
class FieldTypeDefaultsTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->plugin = new FieldTypeDefaults([], 'd7_field_type_defaults', []);
}
/**
* Tests various default cases.
*
* @covers ::transform
*/
public function testDefaults() {
// 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 will return the second item, which is the source
// formatter type.
$this->assertEquals('datetime_default', $this->plugin->transform(['datetime', 'datetime_default'], $this->migrateExecutable, $this->row, 'property'));
}
}
......@@ -22,6 +22,15 @@
*/
class LinkField extends D6LinkField {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'link_default' => 'link',
];
}
/**
* {@inheritdoc}
*/
......
......@@ -18,6 +18,15 @@
*/
class TaxonomyTermReference extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'taxonomy_term_reference_link' => 'entity_reference_label',
];
}
/**
* {@inheritdoc}
*/
......
......@@ -15,4 +15,15 @@
* destination_module = "telephone"
* )
*/
class PhoneField extends FieldPluginBase {}
class PhoneField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'phone' => 'basic_string',
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment