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 0000000000000000000000000000000000000000..9207d0df89d5074736418bf97aeae443ca856536 --- /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 c0e8447c741a9fece0447e0525152bbfd8c4b54d..5f395fc8fe33133f37dab734eb04992696e6b4e4 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 @@ * 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 @@ public function query() { * {@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 6c009573998e80b485aab33e7fbdcef91c55d48e..cf891c41678a46e72c120a6b1d67ce626976d8a8 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -10062,6 +10062,22 @@ '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 @@ '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( @@ -27708,14 +27738,6 @@ 'plural' => '0', '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 ', @@ -27724,30 +27746,6 @@ 'plural' => '0', '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', @@ -27876,6 +27874,14 @@ 'plural' => '0', 'i18n_status' => '0', )) +->values(array( + 'lid' => '1690', + 'translation' => 'Noir', + 'language' => 'fr', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) ->values(array( 'lid' => '1691', 'translation' => 'Mhlophe', @@ -27884,6 +27890,22 @@ 'plural' => '0', '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', @@ -27900,6 +27922,22 @@ '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 @@ '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 b37b45b638a97178c4315d86a450ad005c236be9..96b3b1f869fe474357aaa79059dddf8a1c39602c 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 @@ protected function getEntityCounts() { '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 0000000000000000000000000000000000000000..fb9874339302d33dbd0d805a0394a9b443d9d2c0 --- /dev/null +++ b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php @@ -0,0 +1,41 @@ + $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 0000000000000000000000000000000000000000..b3eef04f535a13414f0159d307378100d060d668 --- /dev/null +++ b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php @@ -0,0 +1,58 @@ +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 0000000000000000000000000000000000000000..d06b012b69d17375885755d8d25b7ab795b3ff84 --- /dev/null +++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateProfileFieldOptionTranslationTest.php @@ -0,0 +1,80 @@ +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 0000000000000000000000000000000000000000..66cee39b467869a52db971006b239308014487d9 --- /dev/null +++ b/core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php @@ -0,0 +1,72 @@ + 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; + } + +}