diff -u b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php --- b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php +++ b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php @@ -9,7 +9,7 @@ * * @MigrateSource( * id = "d6_i18n_profile_field", - * source_provider = "profile" + * source_provider = "i18n" * ) */ class I18nProfileField extends DrupalSqlBase { @@ -19,9 +19,9 @@ */ public function query() { $query = $this->select('profile_fields', 'pf') - ->fields('pf', array('fid', 'name')) - ->fields('i18n', array('property')) - ->fields('lt', array('lid', 'translation', 'language')); + ->fields('pf', ['fid', 'name']) + ->fields('i18n', ['property']) + ->fields('lt', ['lid', 'translation', 'language']); $query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name'); $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid'); return $query; @@ -33,6 +33,7 @@ public function fields() { return array( 'fid' => $this->t('Profile field ID.'), + 'lid' => $this->t('Locales target language ID.'), 'language' => $this->t('Language for this field.'), 'translation' => $this->t('Translation of either the title or explanation.'), ); @@ -44,7 +45,8 @@ public function getIds() { $ids['fid']['type'] = 'integer'; $ids['language']['type'] = 'string'; - $ids['translation']['type'] = 'string'; + $ids['lid']['type'] = 'integer'; + $ids['lid']['alias'] = 'lt'; return $ids; } diff -u b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nUserProfileFieldInstanceTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nUserProfileFieldInstanceTest.php --- b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nUserProfileFieldInstanceTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nUserProfileFieldInstanceTest.php @@ -32,31 +32,40 @@ * Tests migration of translated user profile fields. */ public function testUserProfileFields() { - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_love_migrations'); - $this->assertIdentical("J'aime les migrations", $config_translation->get('label')); - $this->assertIdentical("Si vous cochez cette case, vous aimez les migrations.", $config_translation->get('description')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_color'); - $this->assertIdentical('fr - Favorite color', $config_translation->get('label')); - $this->assertIdentical('Inscrivez votre couleur préférée', $config_translation->get('description')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_biography'); - $this->assertIdentical('fr - Biography', $config_translation->get('label')); - $this->assertIdentical('fr - Tell people a little bit about yourself', $config_translation->get('description')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_sell_address'); - $this->assertIdentical('fr - Sell your email address?', $config_translation->get('label')); - $this->assertIdentical("fr - If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $config_translation->get('description')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_sold_to'); - $this->assertIdentical('fr - Sales Category', $config_translation->get('label')); - $this->assertIdentical("fr - Select the sales categories to which this user's address was sold.", $config_translation->get('description')); - $this->assertIdentical('fr - Pill spammers Fitness spammers Back\slash Forward/slash Dot.in.the.middle', $config_translation->get('options')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_bands'); - $this->assertIdentical('Mes groupes préférés', $config_translation->get('label')); - $this->assertIdentical("fr - Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $config_translation->get('description')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_birthdate'); - $this->assertIdentical('fr - Birthdate', $config_translation->get('label')); - $this->assertIdentical('fr - Enter your birth date and we\'ll send you a coupon.', $config_translation->get('description')); - $config_translation = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'field.field.user.user.profile_blog'); - $this->assertIdentical('fr - Blog', $config_translation->get('label')); - $this->assertIdentical('fr - Paste the full URL, including http://, of your personal blog.', $config_translation->get('description')); + $language_manager = $this->container->get('language_manager'); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_love_migrations'); + $this->assertSame("J'aime les migrations", $config_translation->get('label')); + $this->assertSame("Si vous cochez cette case, vous aimez les migrations.", $config_translation->get('description')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_color'); + $this->assertSame('fr - Favorite color', $config_translation->get('label')); + $this->assertSame('Inscrivez votre couleur préférée', $config_translation->get('description')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_biography'); + $this->assertSame('fr - Biography', $config_translation->get('label')); + $this->assertSame('fr - Tell people a little bit about yourself', $config_translation->get('description')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_sell_address'); + $this->assertSame('fr - Sell your email address?', $config_translation->get('label')); + $this->assertSame("fr - If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $config_translation->get('description')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_sold_to'); + $this->assertSame('fr - Sales Category', $config_translation->get('label')); + $this->assertSame("fr - Select the sales categories to which this user's address was sold.", $config_translation->get('description')); + $this->assertSame('fr - Pill spammers Fitness spammers Back\slash Forward/slash Dot.in.the.middle', $config_translation->get('options')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_bands'); + $this->assertSame('Mes groupes préférés', $config_translation->get('label')); + $this->assertSame("fr - Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $config_translation->get('description')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_birthdate'); + $this->assertSame('fr - Birthdate', $config_translation->get('label')); + $this->assertSame('fr - Enter your birth date and we\'ll send you a coupon.', $config_translation->get('description')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_blog'); + $this->assertSame('fr - Blog', $config_translation->get('label')); + $this->assertSame('fr - Paste the full URL, including http://, of your personal blog.', $config_translation->get('description')); } } diff -u b/core/modules/config_translation/tests/src/Plugin/migrate/source/d6/I18nProfileFieldTest.php b/core/modules/config_translation/tests/src/Plugin/migrate/source/d6/I18nProfileFieldTest.php --- b/core/modules/config_translation/tests/src/Plugin/migrate/source/d6/I18nProfileFieldTest.php +++ b/core/modules/config_translation/tests/src/Plugin/migrate/source/d6/I18nProfileFieldTest.php @@ -17,65 +17,62 @@ */ public static $modules = ['config_translation', 'migrate_drupal', 'user']; - protected $databaseContents = [ - 'profile_fields' => [ - [ - 'fid' => 42, - 'title' => 'I love migrations', - 'name' => 'profile_love_migrations', + /** + * {@inheritdoc} + */ + public function providerSource() { + $test = []; + $test[0]['source_data'] = [ + 'profile_fields' => [ + [ + 'fid' => 42, + 'title' => 'I love migrations', + 'name' => 'profile_love_migrations', + ], ], - ], - 'i18n_strings' => [ - [ - 'lid' => 10, - 'objectid' => 'profile_love_migrations', - 'type' => 'field', - 'property' => 'title', + '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', + ], + ], + ]; + $test[0]['expected_results'] = [ [ - 'lid' => 11, - 'objectid' => 'profile_love_migrations', - 'type' => 'field', - 'property' => 'explanation' - ] - ], - 'locales_target' => [ - [ - 'lid' => 10, + 'property' => 'title', 'translation' => "J'aime les migrations.", 'language' => 'fr', + 'fid' => '42', + 'name' => 'profile_love_migrations', ], [ - 'lid' => 11, + 'property' => 'explanation', 'translation' => 'Si vous cochez cette case, vous aimez les migrations.', 'language' => 'fr', + 'fid' => '42', + 'name' => 'profile_love_migrations', ], - ], - ]; - - 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} - */ - public function providerSource() { - $test[0][0] = $this->databaseContents; - $test[0][1] = $this->expectedResults; + ]; return $test; } diff -u b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php --- b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php @@ -3,6 +3,7 @@ namespace Drupal\migrate\Plugin\migrate\destination; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Language\LanguageManagerInterface; @@ -32,6 +33,13 @@ */ protected $languageManager; + /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface; + */ + protected $configFactory; + /** * Construct a new entity. * @@ -41,18 +49,21 @@ * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param MigrationInterface $migration + * @param \Drupal\migrate\Plugin\MigrationInterface $migration * The migration. - * @param EntityStorageInterface $storage + * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. - * @param LanguageManagerInterface $language_manager + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The configuration factory. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles); $this->languageManager = $language_manager; + $this->configFactory = $config_factory; } /** @@ -67,7 +78,8 @@ $migration, $container->get('entity.manager')->getStorage($entity_type_id), array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('config.factory') ); } @@ -126,7 +138,7 @@ $translation = FALSE; if ($row->hasDestinationProperty('langcode') && $this->languageManager instanceof ConfigurableLanguageManagerInterface) { $config = $entity->getConfigDependencyName(); - $langcode = \Drupal::config($config)->get('langcode'); + $langcode = $this->configFactory->get('langcode'); if ($langcode != $row->getDestinationProperty('langcode')) { $translation = TRUE; } diff -u b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php --- b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php @@ -2,6 +2,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\destination; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Language\LanguageManagerInterface; @@ -40,14 +41,17 @@ * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. - * @param LanguageManagerInterface $language_manager + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager * The field type plugin manager. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The configuration factory. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, FieldTypePluginManagerInterface $field_type_plugin_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $field_type_plugin_manager); + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory,FieldTypePluginManagerInterface $field_type_plugin_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $config_factory, $field_type_plugin_manager); $this->languageManager = $language_manager; + $this->configFactory = $config_factory; $this->fieldTypePluginManager = $field_type_plugin_manager; } @@ -64,6 +68,7 @@ $container->get('entity.manager')->getStorage($entity_type_id), array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)), $container->get('language_manager'), + $container->get('config.factory'), $container->get('plugin.manager.field.field_type') ); }