summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-04-25 07:23:45 -0400
committerNathaniel Catchpole2017-04-25 07:23:45 -0400
commit882537ab5699f4a8e63dfb86d52f1679bb8c718a (patch)
treec915832d445c151d7a125b146e03aa00ff2a6b85
parent7e3527ed2f2d64b30a156ff92bb8f657008d267c (diff)
Issue #2665196 by rakesh.gectcr, quietone, Manuel Garcia, Jo Fitzgerald, webflo, mikeryan, phenaproxima, heddn: Migration for email fields is missing
-rw-r--r--core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php54
-rw-r--r--core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php4
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php4
-rw-r--r--core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php3
-rw-r--r--core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php3
5 files changed, 66 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php b/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php
new file mode 100644
index 0000000..3b490f0
--- /dev/null
+++ b/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Drupal\Core\Field\Plugin\migrate\field;
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
+
+/**
+ * @MigrateField(
+ * id = "email",
+ * core = {6,7},
+ * type_map = {
+ * "email" = "email"
+ * }
+ * )
+ */
+class Email extends FieldPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getFieldWidgetMap() {
+ return [
+ 'email_textfield' => 'email_default',
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getFieldFormatterMap() {
+ return [
+ 'email_formatter_default' => 'basic_string',
+ 'email_formatter_contact' => 'basic_string',
+ 'email_formatter_plain' => 'basic_string',
+ 'email_formatter_spamspan' => 'basic_string',
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
+ $process = [
+ 'plugin' => 'iterator',
+ 'source' => $field_name,
+ 'process' => [
+ 'value' => 'email',
+ ],
+ ];
+ $migration->setProcessOfProperty($field_name, $process);
+ }
+
+}
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php
index 6900161..835956c 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php
@@ -70,6 +70,10 @@ class MigrateFieldTest extends MigrateDrupal6TestBase {
$this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
$this->assertIdentical('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
+ // Email field.
+ $field_storage = FieldStorageConfig::load('node.field_test_email');
+ $this->assertSame("email", $field_storage->getType(), t('Field type is @fieldtype. It should be email.', ['@fieldtype' => $field_storage->getType()]));
+
// Float field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index 42c6a2b..a2fbc81 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -3406,7 +3406,7 @@ $connection->insert('content_type_story')
'field_test_date_value' => NULL,
'field_test_datestamp_value' => NULL,
'field_test_datetime_value' => NULL,
- 'field_test_email_email' => NULL,
+ 'field_test_email_email' => 'PrincessRuwenne@example.com',
'field_test_filefield_fid' => '5',
'field_test_filefield_list' => '1',
'field_test_filefield_data' => 'a:1:{s:11:"description";s:4:"desc";}',
@@ -3435,7 +3435,7 @@ $connection->insert('content_type_story')
'field_test_date_value' => NULL,
'field_test_datestamp_value' => NULL,
'field_test_datetime_value' => NULL,
- 'field_test_email_email' => NULL,
+ 'field_test_email_email' => 'PrincessRuwenne@example.com',
'field_test_filefield_fid' => NULL,
'field_test_filefield_list' => NULL,
'field_test_filefield_data' => NULL,
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php
index cf7f5ef..8ed773f 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php
@@ -81,6 +81,9 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$this->assertIdentical('desc', $node->field_test_filefield->description);
$this->assertIdentical('4', $node->field_test_filefield->target_id);
+ // Test that an email field is migrated.
+ $this->assertSame('PrincessRuwenne@example.com', $node->field_test_email->value);
+
$node = Node::load(2);
$this->assertIdentical('Test title rev 3', $node->getTitle());
$this->assertIdentical('test rev 3', $node->body->value);
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
index 96875bd..9ca1d4a 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
@@ -150,6 +150,9 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
$this->assertIdentical('93', $node->field_images->height);
$this->assertIdentical('http://google.com', $node->field_link->uri);
$this->assertIdentical('Click Here', $node->field_link->title);
+ // Test that an email field is migrated.
+ $this->assertSame('default@example.com', $node->field_email->value);
+ $this->assertSame('another@example.com', $node->field_email[1]->value);
$node = Node::load(2);
$this->assertSame('en', $node->langcode->value);