summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2018-10-04 14:06:30 (GMT)
committerNathaniel Catchpole2018-10-04 14:06:39 (GMT)
commit3c0af3732ea3e4d4c6f153f4b37beb5ebc68984e (patch)
tree36786a9c98f3d2ec6085fcf08e2624c584a9a692
parentfd751a2def28e1baa59e83fdc6bc9b227a276c92 (diff)
Issue #2959410 by quietone, Jo Fitzgerald, masipila, mikeryan: Migrate D6 i18n CCK fields label and description
(cherry picked from commit 1aee6103bfbc562ca6567c895e4642df557d9ac1)
-rw-r--r--core/modules/config_translation/migrations/d6_field_instance_label_description_translation.yml57
-rw-r--r--core/modules/field/src/Plugin/migrate/source/d6/FieldLabelDescriptionTranslation.php60
-rw-r--r--core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php134
-rw-r--r--core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstanceLabelDescriptionTranslationTest.php79
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php19
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php2
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php2
7 files changed, 334 insertions, 19 deletions
diff --git a/core/modules/config_translation/migrations/d6_field_instance_label_description_translation.yml b/core/modules/config_translation/migrations/d6_field_instance_label_description_translation.yml
new file mode 100644
index 0000000..41d7292
--- /dev/null
+++ b/core/modules/config_translation/migrations/d6_field_instance_label_description_translation.yml
@@ -0,0 +1,57 @@
+id: d6_field_instance_label_description_translation
+label: Field label and description translation
+migration_tags:
+ - Drupal 6
+ - Configuration
+ - Multilingual
+source:
+ plugin: d6_field_instance_label_description_translation
+ constants:
+ entity_type: node
+process:
+ langcode:
+ plugin: skip_on_empty
+ source: language
+ method: row
+ translation:
+ plugin: skip_on_empty
+ source: translation
+ method: row
+ field_name_parts:
+ plugin: explode
+ source: objectid
+ delimiter: '-'
+ field_name:
+ plugin: extract
+ source: '@field_name_parts'
+ index:
+ - 1
+ bundle:
+ plugin: extract
+ source: '@field_name_parts'
+ index:
+ - 0
+ exists:
+ -
+ plugin: migration_lookup
+ migration: d6_field_instance
+ source:
+ - '@field_name'
+ - '@bundle'
+ -
+ plugin: skip_on_empty
+ method: row
+ entity_type: 'constants/entity_type'
+ property:
+ plugin: static_map
+ source: property
+ bypass: true
+ map:
+ widget_label: label
+ widget_description: description
+destination:
+ plugin: entity:field_config
+ translations: true
+migration_dependencies:
+ required:
+ - d6_field_instance
diff --git a/core/modules/field/src/Plugin/migrate/source/d6/FieldLabelDescriptionTranslation.php b/core/modules/field/src/Plugin/migrate/source/d6/FieldLabelDescriptionTranslation.php
new file mode 100644
index 0000000..e996129
--- /dev/null
+++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldLabelDescriptionTranslation.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\field\Plugin\migrate\source\d6;
+
+use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
+
+/**
+ * Gets field label and description translations.
+ *
+ * @MigrateSource(
+ * id = "d6_field_instance_label_description_translation",
+ * source_module = "i18ncck"
+ * )
+ */
+class FieldLabelDescriptionTranslation extends DrupalSqlBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ // Get translations for field labels and descriptions.
+ $query = $this->select('i18n_strings', 'i18n')
+ ->fields('i18n', ['property', 'objectid', 'type'])
+ ->fields('lt', ['lid', 'translation', 'language'])
+ ->condition('i18n.type', 'field')
+ ->isNotNull('language')
+ ->isNotNull('translation');
+ $condition = $query->orConditionGroup()
+ ->condition('property', 'widget_label')
+ ->condition('property', 'widget_description');
+ $query->condition($condition);
+ $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
+
+ return $query;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ return [
+ 'property' => $this->t('Profile field ID.'),
+ 'lid' => $this->t('Locales target language ID.'),
+ 'language' => $this->t('Language for this field.'),
+ 'translation' => $this->t('Translation of either the title or explanation.'),
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['property']['type'] = 'string';
+ $ids['language']['type'] = 'string';
+ $ids['lid']['type'] = 'integer';
+ $ids['lid']['alias'] = 'lt';
+ return $ids;
+ }
+
+}
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php
new file mode 100644
index 0000000..5d51972
--- /dev/null
+++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php
@@ -0,0 +1,134 @@
+<?php
+
+namespace Drupal\Tests\field\Kernel\Migrate\d6;
+
+use Drupal\KernelTests\KernelTestBase;
+use Drupal\Core\Database\Database;
+use Drupal\Tests\migrate\Kernel\MigrateDumpAlterInterface;
+use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
+
+/**
+ * Tests migration field label and description i18n translations.
+ *
+ * @group migrate_drupal_6
+ * @group legacy
+ */
+class MigrateFieldInstanceLabelDescriptionTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [
+ 'config_translation',
+ 'locale',
+ 'language',
+ 'menu_ui',
+ 'node',
+ 'field',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->migrateFields();
+
+ $this->installEntitySchema('node');
+ $this->installConfig(['node']);
+ $this->installSchema('node', ['node_access']);
+ $this->installSchema('system', ['sequences']);
+ $this->executeMigration('language');
+ $this->executeMigration('d6_field_instance_label_description_translation');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function migrateDumpAlter(KernelTestBase $test) {
+ $db = Database::getConnection('default', 'migrate');
+ // Alter the database to test the migration is successful when a translated
+ // field is deleted but the translation data for that field remains in both
+ // the i18n_strings and locales_target tables.
+ $db->delete('content_node_field_instance')
+ ->condition('field_name', 'field_test')
+ ->condition('type_name', 'story')
+ ->execute();
+ }
+
+ /**
+ * Tests migration of file variables to file.settings.yml.
+ */
+ public function testFieldInstanceLabelDescriptionTranslationMigration() {
+ $language_manager = $this->container->get('language_manager');
+
+ // Tests fields on 'story' node type.
+ // Check that the deleted field with translations was skipped.
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test');
+ $this->assertNull($config_translation->get('label'));
+ $this->assertNull($config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_two');
+ $this->assertSame("fr - Integer Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example integer field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_four');
+ $this->assertSame("fr - Float Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example float field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_email');
+ $this->assertSame("fr - Email Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example email field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_imagefield');
+ $this->assertSame("fr - Image Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example image field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.field.node.story.field_test_imagefield');
+ $this->assertSame("zu - Image Field", $config_translation->get('label'));
+ $this->assertSame("zu - An example image field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_filefield');
+ $this->assertSame("fr - File Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example file field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_link');
+ $this->assertSame("fr - Link Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example link field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_date');
+ $this->assertSame("fr - Date Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example date field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_datetime');
+ $this->assertSame("fr - Datetime Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example datetime field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_datestamp');
+ $this->assertSame("fr - Date Stamp Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example date stamp field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_date');
+ $this->assertSame("fr - Date Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example date field.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_phone');
+ $this->assertSame("fr - Phone Field", $config_translation->get('label'));
+ $this->assertSame("fr - An example phone field.", $config_translation->get('description'));
+
+ // Tests fields on 'test_page' node type.
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_page.field_test');
+ $this->assertSame("Champ de texte", $config_translation->get('label'));
+ $this->assertSame("fr - An example text field.", $config_translation->get('description'));
+
+ // Tests fields on 'test_planet' node type.
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_planet.field_multivalue');
+ $this->assertSame("fr - Decimal Field", $config_translation->get('label'));
+ $this->assertSame("Un exemple plusieurs valeurs champ d├ęcimal.", $config_translation->get('description'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_planet.field_test_text_single_checkbox');
+ $this->assertNull($config_translation->get('label'));
+ $this->assertSame('fr - An example text field using a single on/off checkbox.', $config_translation->get('description'));
+ }
+
+}
diff --git a/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstanceLabelDescriptionTranslationTest.php b/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstanceLabelDescriptionTranslationTest.php
new file mode 100644
index 0000000..c7dbf27
--- /dev/null
+++ b/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstanceLabelDescriptionTranslationTest.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Drupal\Tests\field\Kernel\Plugin\migrate\source\d6;
+
+use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
+
+/**
+ * Tests the field label and description translation source plugin.
+ *
+ * @covers \Drupal\field\Plugin\migrate\source\d6\FieldLabelDescriptionTranslation
+ * @group migrate_drupal
+ */
+class FieldInstanceLabelDescriptionTranslationTest extends MigrateSqlSourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['config_translation', 'migrate_drupal', 'field'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+ $test = [];
+
+ // The source data.
+ $test[0]['source_data'] = [
+ 'i18n_strings' => [
+ [
+ 'lid' => 10,
+ 'objectid' => 'story-field_test_two',
+ 'type' => 'field',
+ 'property' => 'widget_label',
+ ],
+ [
+ 'lid' => 11,
+ 'objectid' => 'story-field_test_two',
+ 'type' => 'field',
+ 'property' => 'widget_description',
+ ],
+ [
+ 'lid' => 12,
+ 'objectid' => 'story-field_test_two',
+ 'type' => 'field',
+ 'property' => 'widget_description',
+ ],
+ ],
+ 'locales_target' => [
+ [
+ 'lid' => 10,
+ 'translation' => "fr - Integer Field",
+ 'language' => 'fr',
+ ],
+ [
+ 'lid' => 11,
+ 'translation' => 'fr - An example integer field.',
+ 'language' => 'fr',
+ ],
+ ],
+ ];
+
+ $test[0]['expected_results'] = [
+ [
+ 'property' => 'widget_label',
+ 'translation' => "fr - Integer Field",
+ 'language' => 'fr',
+ 'lid' => '10',
+ ],
+ [
+ 'property' => 'widget_description',
+ 'translation' => 'fr - An example integer field.',
+ 'language' => 'fr',
+ 'lid' => '11',
+ ],
+ ];
+ return $test;
+ }
+
+}
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index 169f884..fee2424 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -15087,13 +15087,6 @@ $connection->insert('locales_source')
'version' => '1',
))
->values(array(
- 'lid' => '626',
- 'location' => 'field:test_planet-field_test_text_single_checkbox:widget_label',
- 'textgroup' => 'cck',
- 'source' => 'Text Single Checkbox Field',
- 'version' => '1',
-))
-->values(array(
'lid' => '627',
'location' => 'field:test_planet-field_test_text_single_checkbox:widget_description',
'textgroup' => 'cck',
@@ -27070,7 +27063,7 @@ $connection->insert('locales_target')
))
->values(array(
'lid' => '575',
- 'translation' => 'fr - An example text field.',
+ 'translation' => 'fr - An example text field.',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
@@ -27182,7 +27175,7 @@ $connection->insert('locales_target')
))
->values(array(
'lid' => '589',
- 'translation' => 'fr - An example image field.',
+ 'translation' => 'fr - An example file field.',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
@@ -27413,14 +27406,6 @@ $connection->insert('locales_target')
'i18n_status' => '0',
))
->values(array(
- 'lid' => '626',
- 'translation' => 'fr - Text Single Checkbox Field',
- 'language' => 'fr',
- 'plid' => '0',
- 'plural' => '0',
- 'i18n_status' => '0',
-))
-->values(array(
'lid' => '627',
'translation' => 'fr - An example text field using a single on/off checkbox.',
'language' => 'fr',
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php
index d2fe095..91657f7 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php
@@ -65,6 +65,7 @@ class MigrateUpgrade6ReviewPageTest extends MigrateUpgradeReviewPageTestBase {
'forum',
'i18n',
'i18nblocks',
+ 'i18ncck',
'i18nmenu',
'i18nprofile',
'i18nstrings',
@@ -142,7 +143,6 @@ class MigrateUpgrade6ReviewPageTest extends MigrateUpgradeReviewPageTestBase {
'devel',
'devel_generate',
'devel_node_access',
- 'i18ncck',
'i18ncontent',
'i18npoll',
'i18nsync',
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
index 4aef9dd..02f9aaf 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
@@ -137,6 +137,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
'forum',
'i18n',
'i18nblocks',
+ 'i18ncck',
'i18nmenu',
'i18nprofile',
'i18nstrings',
@@ -179,7 +180,6 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
*/
protected function getMissingPaths() {
return [
- 'i18ncck',
'i18ncontent',
];
}