diff --git a/core/modules/language/migration_templates/default_language.yml b/core/modules/language/migration_templates/default_language.yml new file mode 100644 index 0000000..d7e52ad --- /dev/null +++ b/core/modules/language/migration_templates/default_language.yml @@ -0,0 +1,25 @@ +id: default_language +label: Default language +migration_tags: + - Drupal 6 + - Drupal 7 +source: + plugin: variable + variables: + - language_default +process: + default_langcode: + - + plugin: callback + callable: get_object_vars + source: language_default + - + plugin: extract + index: + - language +destination: + plugin: default_langcode + config_name: system.site +migration_dependencies: + required: + - language diff --git a/core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php b/core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php new file mode 100644 index 0000000..a5a50a9 --- /dev/null +++ b/core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php @@ -0,0 +1,36 @@ +getDestination(); + $langcode = $destination['default_langcode']; + + // Check if the language exists. + if (ConfigurableLanguage::load($langcode) === NULL) { + throw new MigrateException("The language '$langcode' does not exist on this site."); + } + + $this->config->set('default_langcode', $destination['default_langcode']); + $this->config->save(); + return [$this->config->getName()]; + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php b/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php new file mode 100644 index 0000000..deb6020 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php @@ -0,0 +1,56 @@ +sourceDatabase->update('variable') + ->fields(array( + 'value' => $value + )) + ->condition('name', 'language_default' ) + ->execute(); + + $this->startCollectingMessages(); + $this->executeMigrations(['language', 'default_language']); + + if ($existing) { + // If the default language exists, we should be able to load it and the + // default_langcode config should be set. + $default_language = ConfigurableLanguage::load($langcode); + $this->assertNotNull($default_language); + $this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode')); + } + else { + // Otherwise, the migration log should contain an error message. + $messages = $this->migration->getIdMap()->getMessageIterator(); + $count = 0; + foreach ($messages as $message) { + $count++; + $this->assertEqual($message->message, "The language '$langcode' does not exist on this site."); + $this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR); + } + $this->assertEqual($count, 1); + } + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php new file mode 100644 index 0000000..de2dcfe --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php @@ -0,0 +1,38 @@ +doTestMigration('fr'); + } + + /** + * Tests the migration of the language_default variable to the + * system.site.default_langcode config key, with a non-existent language. + */ + public function testMigrationWithNonExistentLanguage() { + $this->doTestMigration('tv', FALSE); + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php new file mode 100644 index 0000000..f4b4162 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php @@ -0,0 +1,38 @@ +doTestMigration('is'); + } + + /** + * Tests the migration of the language_default variable to the + * system.site.default_langcode config key, with a non-existent language. + */ + public function testMigrationWithNonExistentLanguage() { + $this->doTestMigration('tv', FALSE); + } + +} diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index fdcb26e..4c1f4d3 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -170,6 +170,10 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'dblog', 'destination_module' => 'dblog', ], + 'default_language' => [ + 'source_module' => 'locale', + 'destination_module' => 'language', + ], 'd6_field' => [ 'source_module' => 'content', 'destination_module' => 'field',