Commit 75a42131 authored by catch's avatar catch

Issue #2845975 by quietone, Jo Fitzgerald, aleevas, maxocub, Gábor Hojtsy:...

Issue #2845975 by quietone, Jo Fitzgerald, aleevas, maxocub, Gábor Hojtsy: Migrate Drupal 6 user profile field value option translations
parent 0b6c398e
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
......@@ -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;
}
}
......@@ -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(
......@@ -68,8 +68,8 @@ protected function getEntityCounts() {
'contact_message' => 0,
'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,
......
<?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;
}
}
<?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'],
];
}
}
<?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'));
}
}
<?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;
}
}
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