Skip to content

Commit e086c45

Browse files
author
Nathaniel Catchpole
committed
Issue #2845975 by quietone, Jo Fitzgerald, aleevas, maxocub, Gábor Hojtsy: Migrate Drupal 6 user profile field value option translations
(cherry picked from commit 75a4213)
1 parent 9b45c6b commit e086c45

File tree

8 files changed

+399
-44
lines changed

8 files changed

+399
-44
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
id: d6_profile_field_option_translation
2+
label: Profile field configuration
3+
migration_tags:
4+
- Drupal 6
5+
- Configuration
6+
- Multilingual
7+
source:
8+
plugin: d6_profile_field_option_translation
9+
skip_count: true
10+
constants:
11+
entity_type: user
12+
process:
13+
entity_type: 'constants/entity_type'
14+
status: active
15+
langcode:
16+
plugin: skip_on_empty
17+
source: language
18+
method: row
19+
field_name: objectid
20+
# Use the process from user_profile_field to determine the field type.
21+
type:
22+
plugin: static_map
23+
source: type
24+
map:
25+
selection: list_string
26+
results:
27+
plugin: d6_profile_field_option_translation
28+
source:
29+
- '@type'
30+
- translation
31+
translation:
32+
-
33+
plugin: extract
34+
source: '@results'
35+
index: [1]
36+
-
37+
plugin: skip_on_empty
38+
method: row
39+
property:
40+
-
41+
plugin: extract
42+
source: '@results'
43+
index: [0]
44+
-
45+
plugin: skip_on_empty
46+
method: row
47+
destination:
48+
plugin: entity:field_storage_config
49+
translations: true
50+
migration_dependencies:
51+
required:
52+
- user_profile_field

modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Drupal\config_translation\Plugin\migrate\source\d6;
44

5-
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
5+
use Drupal\user\Plugin\migrate\source\ProfileField;
66

77
/**
88
* Gets i18n strings profile field source from database.
@@ -12,16 +12,16 @@
1212
* source_module = "i18nprofile"
1313
* )
1414
*/
15-
class ProfileFieldTranslation extends DrupalSqlBase {
15+
class ProfileFieldTranslation extends ProfileField {
1616

1717
/**
1818
* {@inheritdoc}
1919
*/
2020
public function query() {
21-
$query = $this->select('profile_fields', 'pf')
22-
->fields('pf', ['fid', 'name'])
23-
->fields('i18n', ['property'])
24-
->fields('lt', ['lid', 'translation', 'language']);
21+
$query = parent::query();
22+
$query->fields('i18n', ['property'])
23+
->fields('lt', ['lid', 'translation', 'language'])
24+
->isNotNull('language');
2525
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
2626
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
2727
return $query;
@@ -31,23 +31,22 @@ public function query() {
3131
* {@inheritdoc}
3232
*/
3333
public function fields() {
34-
return [
35-
'fid' => $this->t('Profile field ID.'),
34+
$fields = [
3635
'lid' => $this->t('Locales target language ID.'),
3736
'language' => $this->t('Language for this field.'),
3837
'translation' => $this->t('Translation of either the title or explanation.'),
3938
];
39+
return parent::fields() + $fields;
4040
}
4141

4242
/**
4343
* {@inheritdoc}
4444
*/
4545
public function getIds() {
46-
$ids['fid']['type'] = 'integer';
4746
$ids['language']['type'] = 'string';
4847
$ids['lid']['type'] = 'integer';
4948
$ids['lid']['alias'] = 'lt';
50-
return $ids;
49+
return parent::getIds() + $ids;
5150
}
5251

5352
}

modules/migrate_drupal/tests/fixtures/drupal6.php

Lines changed: 85 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10062,6 +10062,22 @@
1006210062
'objectindex' => '14',
1006310063
'format' => '0',
1006410064
))
10065+
->values(array(
10066+
'lid' => '1695',
10067+
'objectid' => 'profile_count_trees',
10068+
'type' => 'field',
10069+
'property' => 'title',
10070+
'objectindex' => '0',
10071+
'format' => '0',
10072+
))
10073+
->values(array(
10074+
'lid' => '1696',
10075+
'objectid' => 'profile_count_trees',
10076+
'type' => 'field',
10077+
'property' => 'options',
10078+
'objectindex' => '0',
10079+
'format' => '0',
10080+
))
1006510081
->execute();
1006610082
$connection->schema()->createTable('i18n_variable', array(
1006710083
'fields' => array(
@@ -22649,6 +22665,20 @@
2264922665
'source' => 'The home of Captain Christopher Pike.',
2265022666
'version' => '1',
2265122667
))
22668+
->values(array(
22669+
'lid' => '1695',
22670+
'location' => 'field:profile_:title',
22671+
'textgroup' => 'profile',
22672+
'source' => 'Number of trees',
22673+
'version' => '1',
22674+
))
22675+
->values(array(
22676+
'lid' => '1696',
22677+
'location' => 'field:profile_:options',
22678+
'textgroup' => 'profile',
22679+
'source' => "10\r\n20\r\n50\r\n100\r\n1000",
22680+
'version' => '1',
22681+
))
2265222682
->execute();
2265322683
$connection->schema()->createTable('locales_target', array(
2265422684
'fields' => array(
@@ -27708,14 +27738,6 @@
2770827738
'plural' => '0',
2770927739
'i18n_status' => '0',
2771027740
))
27711-
->values(array(
27712-
'lid' => '1672',
27713-
'translation' => 'fr - Type',
27714-
'language' => 'fr',
27715-
'plid' => '0',
27716-
'plural' => '0',
27717-
'i18n_status' => '0',
27718-
))
2771927741
->values(array(
2772027742
'lid' => '1678',
2772127743
'translation' => 'fr - I really, really, really love migrating ',
@@ -27724,30 +27746,6 @@
2772427746
'plural' => '0',
2772527747
'i18n_status' => '0',
2772627748
))
27727-
->values(array(
27728-
'lid' => '1690',
27729-
'translation' => 'Noir',
27730-
'language' => 'fr',
27731-
'plid' => '0',
27732-
'plural' => '0',
27733-
'i18n_status' => '0',
27734-
))
27735-
->values(array(
27736-
'lid' => '1692',
27737-
'translation' => 'fr - Talos IV',
27738-
'language' => 'fr',
27739-
'plid' => '0',
27740-
'plural' => '0',
27741-
'i18n_status' => '0',
27742-
))
27743-
->values(array(
27744-
'lid' => '1694',
27745-
'translation' => 'fr - The home of Captain Christopher Pike.',
27746-
'language' => 'fr',
27747-
'plid' => '0',
27748-
'plural' => '0',
27749-
'i18n_status' => '0',
27750-
))
2775127749
->values(array(
2775227750
'lid' => '66',
2775327751
'translation' => 'zu - CCK - Aucune Intégration aux Vues',
@@ -27876,6 +27874,14 @@
2787627874
'plural' => '0',
2787727875
'i18n_status' => '0',
2787827876
))
27877+
->values(array(
27878+
'lid' => '1690',
27879+
'translation' => 'Noir',
27880+
'language' => 'fr',
27881+
'plid' => '0',
27882+
'plural' => '0',
27883+
'i18n_status' => '0',
27884+
))
2787927885
->values(array(
2788027886
'lid' => '1691',
2788127887
'translation' => 'Mhlophe',
@@ -27884,6 +27890,22 @@
2788427890
'plural' => '0',
2788527891
'i18n_status' => '0',
2788627892
))
27893+
->values(array(
27894+
'lid' => '1672',
27895+
'translation' => 'fr - Type',
27896+
'language' => 'fr',
27897+
'plid' => '0',
27898+
'plural' => '0',
27899+
'i18n_status' => '0',
27900+
))
27901+
->values(array(
27902+
'lid' => '1692',
27903+
'translation' => 'fr - Talos IV',
27904+
'language' => 'fr',
27905+
'plid' => '0',
27906+
'plural' => '0',
27907+
'i18n_status' => '0',
27908+
))
2788727909
->values(array(
2788827910
'lid' => '1693',
2788927911
'translation' => 'zu - Vulcan',
@@ -27900,6 +27922,22 @@
2790027922
'plural' => '0',
2790127923
'i18n_status' => '0',
2790227924
))
27925+
->values(array(
27926+
'lid' => '1694',
27927+
'translation' => 'fr - The home of Captain Christopher Pike.',
27928+
'language' => 'fr',
27929+
'plid' => '0',
27930+
'plural' => '0',
27931+
'i18n_status' => '0',
27932+
))
27933+
->values(array(
27934+
'lid' => '1696',
27935+
'translation' => "fr - 10\r\nfr - 20\r\nfr - 50\r\nfr - 100\r\nfr - 1000",
27936+
'language' => 'fr',
27937+
'plid' => '0',
27938+
'plural' => '0',
27939+
'i18n_status' => '0',
27940+
))
2790327941
->execute();
2790427942
$connection->schema()->createTable('menu_custom', array(
2790527943
'fields' => array(
@@ -45450,6 +45488,21 @@
4545045488
'autocomplete' => '0',
4545145489
'options' => '',
4545245490
))
45491+
->values(array(
45492+
'fid' => '17',
45493+
'title' => 'Number of trees',
45494+
'name' => 'profile_count_trees',
45495+
'explanation' => '',
45496+
'category' => 'Personal information',
45497+
'page' => '',
45498+
'type' => 'selection',
45499+
'weight' => '0',
45500+
'required' => '0',
45501+
'register' => '0',
45502+
'visibility' => '2',
45503+
'autocomplete' => '0',
45504+
'options' => "10\r\n20\r\n50\r\n100\r\n1000",
45505+
))
4545345506
->execute();
4545445507
$connection->schema()->createTable('profile_values', array(
4545545508
'fields' => array(

modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ protected function getEntityCounts() {
6767
'contact_form' => 5,
6868
'configurable_language' => 5,
6969
'editor' => 2,
70-
'field_config' => 90,
71-
'field_storage_config' => 64,
70+
'field_config' => 91,
71+
'field_storage_config' => 65,
7272
'file' => 7,
7373
'filter_format' => 7,
7474
'image_style' => 5,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Drupal\user\Plugin\migrate\process\d6;
4+
5+
use Drupal\migrate\MigrateExecutableInterface;
6+
use Drupal\migrate\ProcessPluginBase;
7+
use Drupal\migrate\Row;
8+
9+
/**
10+
* Determines the settings property and translation.
11+
*
12+
* @MigrateProcessPlugin(
13+
* id = "d6_profile_field_option_translation",
14+
* handle_multiples = TRUE
15+
* )
16+
*/
17+
class ProfileFieldOptionTranslation extends ProcessPluginBase {
18+
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
23+
list($field_type, $translation) = $value;
24+
25+
$new_value = NULL;
26+
if (isset($translation)) {
27+
$allowed_values = [];
28+
$list = explode("\n", $translation);
29+
$list = array_map('trim', $list);
30+
$list = array_filter($list, 'strlen');
31+
if ($field_type === 'list_string') {
32+
foreach ($list as $key => $value) {
33+
$allowed_values[] = ['label' => $value];
34+
}
35+
}
36+
$new_value = ['settings.allowed_values', $allowed_values];
37+
}
38+
return $new_value;
39+
}
40+
41+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Drupal\user\Plugin\migrate\source\d6;
4+
5+
use Drupal\user\Plugin\migrate\source\ProfileField;
6+
7+
/**
8+
* Gets field option label translations.
9+
*
10+
* @MigrateSource(
11+
* id = "d6_profile_field_option_translation",
12+
* source_module = "i18nprofile"
13+
* )
14+
*/
15+
class ProfileFieldOptionTranslation extends ProfileField {
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function query() {
21+
$query = parent::query();
22+
$query
23+
->fields('i18n', ['property', 'objectid'])
24+
->fields('lt', ['translation', 'language'])
25+
->condition('i18n.type', 'field')
26+
->condition('property', 'options')
27+
->isNotNull('translation');
28+
$query->leftjoin('i18n_strings', 'i18n', 'pf.name = i18n.objectid');
29+
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
30+
31+
return $query;
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function fields() {
38+
return parent::fields() +
39+
[
40+
'property' => $this->t('Option ID.'),
41+
'objectid' => $this->t('Field name'),
42+
'language' => $this->t('Language for this field.'),
43+
'translation' => $this->t('Translation of either the title or explanation.'),
44+
];
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function getIds() {
51+
return parent::getIds() +
52+
[
53+
'language' => ['type' => 'string'],
54+
'property' => ['type' => 'string'],
55+
];
56+
}
57+
58+
}

0 commit comments

Comments
 (0)