diff --git a/core/modules/config_translation/migration_templates/i18n_user_profile_field_instance.yml b/core/modules/config_translation/migration_templates/i18n_user_profile_field_instance.yml new file mode 100644 index 0000000..a3e546e --- /dev/null +++ b/core/modules/config_translation/migration_templates/i18n_user_profile_field_instance.yml @@ -0,0 +1,22 @@ +id: i18n_user_profile_field_instance +label: User profile field instance configuration +migration_tags: + - Drupal 6 +source: + plugin: d6_i18n_profile_field + constants: + entity_type: user + bundle: user +process: + langcode: language + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' + label: title + description: explanation + field_name: name +destination: + plugin: entity:field_config +migration_dependencies: + required: + - user_profile_field + - user_profile_field_instance diff --git a/core/modules/config_translation/src/Plugin/migrate/source/d6/i18nProfileField.php b/core/modules/config_translation/src/Plugin/migrate/source/d6/i18nProfileField.php new file mode 100644 index 0000000..b4c22f4 --- /dev/null +++ b/core/modules/config_translation/src/Plugin/migrate/source/d6/i18nProfileField.php @@ -0,0 +1,95 @@ +fieldTable) || empty($this->valueTable)) { + if ($this->getModuleSchemaVersion('system') >= 7000) { + $this->fieldTable = 'profile_field'; + } + else { + $this->fieldTable = 'profile_fields'; + } + } + $query = $this->select('i18n_strings', 'i18n') + ->fields('i18n', array('property')) + ->fields('lt', array('lid', 'translation', 'language')) + ->fields('pf', array('fid', 'name')); + $conditions = "i18n.lid=lt.lid AND (i18n.property='title' or i18n.property='explanation')"; + $query->Join('locales_target', 'lt', $conditions); + $query->leftJoin($this->fieldTable, 'pf', 'pf.name=i18n.objectid'); + + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + if ($row->getSourceProperty('property') === 'title') { + $row->setSourceProperty(('title'),$row->getSourceProperty('translation')); + } + if ($row->getSourceProperty('property') === 'explanation') { + $row->setSourceProperty(('explanation'),$row->getSourceProperty('translation')); + } + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'fid' => $this->t('Profile field ID.'), + 'language' => $this->t('Language for this field.'), + 'translation' => $this->t('Translation of either the title or explanation.'), + ); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['fid']['type'] = 'integer'; + $ids['language']['type'] = 'string'; + $ids['translation']['type'] = 'string'; + return $ids; + } + +} diff --git a/core/modules/config_translation/tests/src/Unit/Plugin/migrate/source/d6/i18nProfileFieldTest.php b/core/modules/config_translation/tests/src/Unit/Plugin/migrate/source/d6/i18nProfileFieldTest.php new file mode 100644 index 0000000..b480698 --- /dev/null +++ b/core/modules/config_translation/tests/src/Unit/Plugin/migrate/source/d6/i18nProfileFieldTest.php @@ -0,0 +1,88 @@ + 'test', + 'source' => [ + 'plugin' => 'd6_i18n_profile_field', + ], + ]; + + protected $databaseContents = [ + 'profile_fields' => [ + [ + 'fid' => 42, + 'title' => 'I love migrations', + 'name' => 'profile_love_migrations', + ], + ], + 'i18n_strings' => [ + [ + 'lid' => 10, + 'objectid' => 'profile_love_migrations', + 'type' => 'field', + 'property' => 'title', + ], + [ + 'lid' => 11, + 'objectid' => 'profile_love_migrations', + 'type' => 'field', + 'property' => 'explanation' + ] + ], + 'locales_target' => [ + [ + 'lid' => 10, + 'translation' => "J'aime les migrations.", + 'language' => 'fr', + ], + [ + 'lid' => 11, + 'translation' => 'Si vous cochez cette case, vous aimez les migrations.', + 'language' => 'fr', + ], + ], + ]; + + protected $expectedResults = [ + [ + 'property' => 'title', + 'translation' => "J'aime les migrations.", + 'language' => 'fr', + 'fid' => '42', + 'name' => 'profile_love_migrations', + ], + [ + 'property' => 'explanation', + 'translation' => 'Si vous cochez cette case, vous aimez les migrations.', + 'language' => 'fr', + 'fid' => '42', + 'name' => 'profile_love_migrations', + ], + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + } + +}