summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2019-01-07 11:27:16 (GMT)
committerNathaniel Catchpole2019-01-07 11:27:33 (GMT)
commitcdd317ebc6ecfc1f903f3993762e5d3ecd4ac0dd (patch)
treede5f7c403d622005b5059c2db69ed5ca81541e98
parent236623f1aa60aa419ee86a87c8af022b6eac3c5c (diff)
Issue #2845975 by quietone, Jo Fitzgerald, aleevas, maxocub, Gábor Hojtsy: Migrate Drupal 6 user profile field value option translations
(cherry picked from commit 75a4213161ea439851970c9ab839f526d576ce25)
-rw-r--r--core/modules/config_translation/migrations/d6_profile_field_option_translation.yml52
-rw-r--r--core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php19
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php117
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php4
-rw-r--r--core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php41
-rw-r--r--core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php58
-rw-r--r--core/modules/user/tests/src/Kernel/Migrate/d6/MigrateProfileFieldOptionTranslationTest.php80
-rw-r--r--core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php72
8 files changed, 399 insertions, 44 deletions
diff --git a/core/modules/config_translation/migrations/d6_profile_field_option_translation.yml b/core/modules/config_translation/migrations/d6_profile_field_option_translation.yml
new file mode 100644
index 0000000..9207d0d
--- /dev/null
+++ b/core/modules/config_translation/migrations/d6_profile_field_option_translation.yml
@@ -0,0 +1,52 @@
+id: d6_profile_field_option_translation
+label: Profile field configuration
+migration_tags:
+ - Drupal 6
+ - Configuration
+ - Multilingual
+source:
+ plugin: d6_profile_field_option_translation
+ skip_count: true
+ constants:
+ entity_type: user
+process:
+ entity_type: 'constants/entity_type'
+ status: active
+ langcode:
+ plugin: skip_on_empty
+ source: language
+ method: row
+ field_name: objectid
+ # Use the process from user_profile_field to determine the field type.
+ type:
+ plugin: static_map
+ source: type
+ map:
+ selection: list_string
+ results:
+ plugin: d6_profile_field_option_translation
+ source:
+ - '@type'
+ - translation
+ translation:
+ -
+ plugin: extract
+ source: '@results'
+ index: [1]
+ -
+ plugin: skip_on_empty
+ method: row
+ property:
+ -
+ plugin: extract
+ source: '@results'
+ index: [0]
+ -
+ plugin: skip_on_empty
+ method: row
+destination:
+ plugin: entity:field_storage_config
+ translations: true
+migration_dependencies:
+ required:
+ - user_profile_field
diff --git a/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php b/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php
index c0e8447..5f395fc 100644
--- a/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php
+++ b/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php
@@ -2,7 +2,7 @@
namespace Drupal\config_translation\Plugin\migrate\source\d6;
-use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
+use Drupal\user\Plugin\migrate\source\ProfileField;
/**
* Gets i18n strings profile field source from database.
@@ -12,16 +12,16 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
* source_module = "i18nprofile"
* )
*/
-class ProfileFieldTranslation extends DrupalSqlBase {
+class ProfileFieldTranslation extends ProfileField {
/**
* {@inheritdoc}
*/
public function query() {
- $query = $this->select('profile_fields', 'pf')
- ->fields('pf', ['fid', 'name'])
- ->fields('i18n', ['property'])
- ->fields('lt', ['lid', 'translation', 'language']);
+ $query = parent::query();
+ $query->fields('i18n', ['property'])
+ ->fields('lt', ['lid', 'translation', 'language'])
+ ->isNotNull('language');
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
@@ -31,23 +31,22 @@ class ProfileFieldTranslation extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
- return [
- 'fid' => $this->t('Profile field ID.'),
+ $fields = [
'lid' => $this->t('Locales target language ID.'),
'language' => $this->t('Language for this field.'),
'translation' => $this->t('Translation of either the title or explanation.'),
];
+ return parent::fields() + $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
- $ids['fid']['type'] = 'integer';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
- return $ids;
+ return parent::getIds() + $ids;
}
}
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index 6c00957..cf891c4 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -10062,6 +10062,22 @@ $connection->insert('i18n_strings')
'objectindex' => '14',
'format' => '0',
))
+->values(array(
+ 'lid' => '1695',
+ 'objectid' => 'profile_count_trees',
+ 'type' => 'field',
+ 'property' => 'title',
+ 'objectindex' => '0',
+ 'format' => '0',
+))
+->values(array(
+ 'lid' => '1696',
+ 'objectid' => 'profile_count_trees',
+ 'type' => 'field',
+ 'property' => 'options',
+ 'objectindex' => '0',
+ 'format' => '0',
+))
->execute();
$connection->schema()->createTable('i18n_variable', array(
'fields' => array(
@@ -22649,6 +22665,20 @@ $connection->insert('locales_source')
'source' => 'The home of Captain Christopher Pike.',
'version' => '1',
))
+->values(array(
+ 'lid' => '1695',
+ 'location' => 'field:profile_:title',
+ 'textgroup' => 'profile',
+ 'source' => 'Number of trees',
+ 'version' => '1',
+))
+->values(array(
+ 'lid' => '1696',
+ 'location' => 'field:profile_:options',
+ 'textgroup' => 'profile',
+ 'source' => "10\r\n20\r\n50\r\n100\r\n1000",
+ 'version' => '1',
+))
->execute();
$connection->schema()->createTable('locales_target', array(
'fields' => array(
@@ -27709,14 +27739,6 @@ $connection->insert('locales_target')
'i18n_status' => '0',
))
->values(array(
- 'lid' => '1672',
- 'translation' => 'fr - Type',
- 'language' => 'fr',
- 'plid' => '0',
- 'plural' => '0',
- 'i18n_status' => '0',
-))
-->values(array(
'lid' => '1678',
'translation' => 'fr - I really, really, really love migrating ',
'language' => 'fr',
@@ -27725,30 +27747,6 @@ $connection->insert('locales_target')
'i18n_status' => '0',
))
->values(array(
- 'lid' => '1690',
- 'translation' => 'Noir',
- 'language' => 'fr',
- 'plid' => '0',
- 'plural' => '0',
- 'i18n_status' => '0',
-))
-->values(array(
- 'lid' => '1692',
- 'translation' => 'fr - Talos IV',
- 'language' => 'fr',
- 'plid' => '0',
- 'plural' => '0',
- 'i18n_status' => '0',
-))
-->values(array(
- 'lid' => '1694',
- 'translation' => 'fr - The home of Captain Christopher Pike.',
- 'language' => 'fr',
- 'plid' => '0',
- 'plural' => '0',
- 'i18n_status' => '0',
-))
-->values(array(
'lid' => '66',
'translation' => 'zu - CCK - Aucune Intégration aux Vues',
'language' => 'zu',
@@ -27877,6 +27875,14 @@ $connection->insert('locales_target')
'i18n_status' => '0',
))
->values(array(
+ 'lid' => '1690',
+ 'translation' => 'Noir',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
'lid' => '1691',
'translation' => 'Mhlophe',
'language' => 'zu',
@@ -27885,6 +27891,22 @@ $connection->insert('locales_target')
'i18n_status' => '0',
))
->values(array(
+ 'lid' => '1672',
+ 'translation' => 'fr - Type',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
+ 'lid' => '1692',
+ 'translation' => 'fr - Talos IV',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
'lid' => '1693',
'translation' => 'zu - Vulcan',
'language' => 'zu',
@@ -27900,6 +27922,22 @@ $connection->insert('locales_target')
'plural' => '0',
'i18n_status' => '0',
))
+->values(array(
+ 'lid' => '1694',
+ 'translation' => 'fr - The home of Captain Christopher Pike.',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
+ 'lid' => '1696',
+ 'translation' => "fr - 10\r\nfr - 20\r\nfr - 50\r\nfr - 100\r\nfr - 1000",
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
->execute();
$connection->schema()->createTable('menu_custom', array(
'fields' => array(
@@ -45450,6 +45488,21 @@ $connection->insert('profile_fields')
'autocomplete' => '0',
'options' => '',
))
+->values(array(
+ 'fid' => '17',
+ 'title' => 'Number of trees',
+ 'name' => 'profile_count_trees',
+ 'explanation' => '',
+ 'category' => 'Personal information',
+ 'page' => '',
+ 'type' => 'selection',
+ 'weight' => '0',
+ 'required' => '0',
+ 'register' => '0',
+ 'visibility' => '2',
+ 'autocomplete' => '0',
+ 'options' => "10\r\n20\r\n50\r\n100\r\n1000",
+))
->execute();
$connection->schema()->createTable('profile_values', array(
'fields' => array(
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 b37b45b..96b3b1f 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
@@ -67,8 +67,8 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
'contact_form' => 5,
'configurable_language' => 5,
'editor' => 2,
- 'field_config' => 90,
- 'field_storage_config' => 64,
+ 'field_config' => 91,
+ 'field_storage_config' => 65,
'file' => 7,
'filter_format' => 7,
'image_style' => 5,
diff --git a/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php
new file mode 100644
index 0000000..fb98743
--- /dev/null
+++ b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Drupal\user\Plugin\migrate\process\d6;
+
+use Drupal\migrate\MigrateExecutableInterface;
+use Drupal\migrate\ProcessPluginBase;
+use Drupal\migrate\Row;
+
+/**
+ * Determines the settings property and translation.
+ *
+ * @MigrateProcessPlugin(
+ * id = "d6_profile_field_option_translation",
+ * handle_multiples = TRUE
+ * )
+ */
+class ProfileFieldOptionTranslation extends ProcessPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+ list($field_type, $translation) = $value;
+
+ $new_value = NULL;
+ if (isset($translation)) {
+ $allowed_values = [];
+ $list = explode("\n", $translation);
+ $list = array_map('trim', $list);
+ $list = array_filter($list, 'strlen');
+ if ($field_type === 'list_string') {
+ foreach ($list as $key => $value) {
+ $allowed_values[] = ['label' => $value];
+ }
+ }
+ $new_value = ['settings.allowed_values', $allowed_values];
+ }
+ return $new_value;
+ }
+
+}
diff --git a/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php
new file mode 100644
index 0000000..b3eef04
--- /dev/null
+++ b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\user\Plugin\migrate\source\d6;
+
+use Drupal\user\Plugin\migrate\source\ProfileField;
+
+/**
+ * Gets field option label translations.
+ *
+ * @MigrateSource(
+ * id = "d6_profile_field_option_translation",
+ * source_module = "i18nprofile"
+ * )
+ */
+class ProfileFieldOptionTranslation extends ProfileField {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ $query = parent::query();
+ $query
+ ->fields('i18n', ['property', 'objectid'])
+ ->fields('lt', ['translation', 'language'])
+ ->condition('i18n.type', 'field')
+ ->condition('property', 'options')
+ ->isNotNull('translation');
+ $query->leftjoin('i18n_strings', 'i18n', 'pf.name = i18n.objectid');
+ $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
+
+ return $query;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ return parent::fields() +
+ [
+ 'property' => $this->t('Option ID.'),
+ 'objectid' => $this->t('Field name'),
+ 'language' => $this->t('Language for this field.'),
+ 'translation' => $this->t('Translation of either the title or explanation.'),
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ return parent::getIds() +
+ [
+ 'language' => ['type' => 'string'],
+ 'property' => ['type' => 'string'],
+ ];
+ }
+
+}
diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateProfileFieldOptionTranslationTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateProfileFieldOptionTranslationTest.php
new file mode 100644
index 0000000..d06b012
--- /dev/null
+++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateProfileFieldOptionTranslationTest.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace Drupal\Tests\user\Kernel\Migrate\d6;
+
+use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
+
+/**
+ * Tests field option translations migration.
+ *
+ * @group migrate_drupal_6
+ */
+class MigrateProfileFieldOptionTranslationTest extends MigrateDrupal6TestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [
+ 'config_translation',
+ 'language',
+ 'locale',
+ 'menu_ui',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ $this->executeMigrations([
+ 'language',
+ 'user_profile_field',
+ 'd6_profile_field_option_translation',
+ ]);
+ }
+
+ /**
+ * Tests the Drupal 6 field option translation.
+ */
+ public function testFieldOptionTranslation() {
+ $language_manager = $this->container->get('language_manager');
+
+ /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.user.profile_count_trees');
+ $allowed_values = [
+ 0 => [
+ 'label' => 'fr - 10',
+ ],
+ 1 => [
+ 'label' => 'fr - 20',
+ ],
+ 2 => [
+ 'label' => 'fr - 50',
+ ],
+ 3 => [
+ 'label' => 'fr - 100',
+ ],
+ 4 => [
+ 'label' => 'fr - 1000',
+ ],
+ ];
+ $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.user.profile_sold_to');
+ $allowed_values = [
+ [
+ 'label' => 'fr - Pill spammers Fitness spammers Back\slash Forward/slash Dot.in.the.middle',
+ ],
+ ];
+ $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
+
+ $config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.storage.user.profile_sold_to');
+ $allowed_values = [
+ [
+ 'label' => 'zu - Pill spammers Fitness spammers Back\slash Forward/slash Dot.in.the.middle',
+ ],
+ ];
+ $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
+ }
+
+}
diff --git a/core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php b/core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php
new file mode 100644
index 0000000..66cee39
--- /dev/null
+++ b/core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Drupal\Tests\user\Kernel\Plugin\migrate\source\d6;
+
+use Drupal\Tests\user\Kernel\Plugin\migrate\source\ProfileFieldTest;
+
+/**
+ * Tests the field option translation source plugin.
+ *
+ * @covers \Drupal\user\Plugin\migrate\source\d6\ProfileFieldOptionTranslation
+ * @group migrate_drupal
+ */
+class ProfileFieldOptionTranslationTest extends ProfileFieldTest {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['user', 'migrate_drupal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+
+ $test = parent::providerSource();
+ // The source data.
+ $test[0]['source_data']['i18n_strings'] = [
+ [
+ 'lid' => 10,
+ 'objectid' => 'profile_color',
+ 'type' => 'field',
+ 'property' => 'options',
+ ],
+ ];
+ $test[0]['source_data']['locales_target'] = [
+ [
+ 'lid' => 10,
+ 'translation' => "fr - red\nfr - blue\nfr - green",
+ 'language' => 'fr',
+ ],
+ ];
+
+ $test[0]['expected_data'] = [
+ [
+ 'fid' => 4,
+ 'title' => 'Color',
+ 'name' => 'profile_color',
+ 'explanation' => 'A selection that allows user to select a color',
+ 'category' => 'profile',
+ 'page' => '',
+ 'type' => 'selection',
+ 'weight' => 0,
+ 'required' => 0,
+ 'register' => 0,
+ 'visibility' => 2,
+ 'autocomplete' => 0,
+ 'options' => [
+ 'red' => 'red',
+ 'blue' => 'blue',
+ 'green' => 'green',
+ 'yellow' => 'yellow',
+ ],
+ 'property' => 'options',
+ 'objectid' => 'profile_color',
+ 'translation' => "fr - red\nfr - blue\nfr - green",
+ 'language' => 'fr',
+ ],
+ ];
+ return $test;
+ }
+
+}