Commit 1aee6103 authored by catch's avatar catch

Issue #2959410 by quietone, Jo Fitzgerald, masipila, mikeryan: Migrate D6 i18n...

Issue #2959410 by quietone, Jo Fitzgerald, masipila, mikeryan: Migrate D6 i18n CCK fields label and description
parent 5cff356c
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
<?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;
}
}
<?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'));
}
}
<?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;
}
}
......@@ -15086,13 +15086,6 @@
'source' => 'An example multi-valued decimal field.',
'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',
......@@ -27070,7 +27063,7 @@
))
->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 @@
))
->values(array(
'lid' => '589',
'translation' => 'fr - An example image field.',
'translation' => 'fr - An example file field.',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
......@@ -27412,14 +27405,6 @@
'plural' => '0',
'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.',
......@@ -65,6 +65,7 @@ protected function getAvailablePaths() {
'forum',
'i18n',
'i18nblocks',
'i18ncck',
'i18nmenu',
'i18nprofile',
'i18nstrings',
......@@ -142,7 +143,6 @@ protected function getMissingPaths() {
'devel',
'devel_generate',
'devel_node_access',
'i18ncck',
'i18ncontent',
'i18npoll',
'i18nsync',
......
......@@ -137,6 +137,7 @@ protected function getAvailablePaths() {
'forum',
'i18n',
'i18nblocks',
'i18ncck',
'i18nmenu',
'i18nprofile',
'i18nstrings',
......@@ -179,7 +180,6 @@ protected function getAvailablePaths() {
*/
protected function getMissingPaths() {
return [
'i18ncck',
'i18ncontent',
];
}
......
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