diff --git a/core/modules/language/migration_templates/d6_language_negotiation_settings.yml b/core/modules/language/migration_templates/d6_language_negotiation_settings.yml index bc5c133..abc71f6 100644 --- a/core/modules/language/migration_templates/d6_language_negotiation_settings.yml +++ b/core/modules/language/migration_templates/d6_language_negotiation_settings.yml @@ -16,6 +16,7 @@ process: url/source: plugin: static_map source: language_negotiation + default_value: path_prefix map: # LANGUAGE_NEGOTIATION_NONE = 0 # LANGUAGE_NEGOTIATION_PATH_DEFAULT = 1 @@ -28,3 +29,6 @@ process: destination: plugin: config config_name: language.negotiation +migration_dependencies: + required: + - language diff --git a/core/modules/language/migration_templates/d6_language_prefixes_and_domains.yml b/core/modules/language/migration_templates/d6_language_prefixes_and_domains.yml deleted file mode 100644 index efafafb..0000000 --- a/core/modules/language/migration_templates/d6_language_prefixes_and_domains.yml +++ /dev/null @@ -1,25 +0,0 @@ -id: d6_language_prefixes_and_domains -label: Language prefixes and domains -migration_tags: - - Drupal 6 -source: - plugin: language - fetch_all: true - negotiation: true -process: - url/prefixes: - plugin: array_build - source: languages - key: language - value: prefix - url/domains: - plugin: language_domains - source: languages - key: language - value: domain -destination: - plugin: config - config_name: language.negotiation -migration_dependencies: - required: - - language diff --git a/core/modules/language/migration_templates/d7_language_negotiation_settings.yml b/core/modules/language/migration_templates/d7_language_negotiation_settings.yml index f03be78..7759965 100644 --- a/core/modules/language/migration_templates/d7_language_negotiation_settings.yml +++ b/core/modules/language/migration_templates/d7_language_negotiation_settings.yml @@ -8,8 +8,25 @@ source: - locale_language_negotiation_session_param - locale_language_negotiation_url_part process: - 'session/parameter': locale_language_negotiation_session_param - 'url/source': locale_language_negotiation_url_part + session/parameter: + plugin: default_value + source: locale_language_negotiation_session_param + default_value: 'language' + selected_langcode: + plugin: default_value + default_value: 'site_default' + url/source: + plugin: static_map + source: locale_language_negotiation_url_part + default_value: path_prefix + map: + # LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX = 0 + # LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN = 1 + 0: path_prefix + 1: domain destination: plugin: config config_name: language.negotiation +migration_dependencies: + required: + - language diff --git a/core/modules/language/migration_templates/language_prefixes_and_domains.yml b/core/modules/language/migration_templates/language_prefixes_and_domains.yml new file mode 100644 index 0000000..edc5b54 --- /dev/null +++ b/core/modules/language/migration_templates/language_prefixes_and_domains.yml @@ -0,0 +1,26 @@ +id: language_prefixes_and_domains +label: Language prefixes and domains +migration_tags: + - Drupal 6 + - Drupal 7 +source: + plugin: language + fetch_all: true + domain_negotiation: true +process: + url/prefixes: + plugin: array_build + source: languages + key: language + value: prefix + url/domains: + plugin: language_domains + source: languages + key: language + value: domain +destination: + plugin: config + config_name: language.negotiation +migration_dependencies: + required: + - language diff --git a/core/modules/language/src/Plugin/migrate/process/LanguageDomains.php b/core/modules/language/src/Plugin/migrate/process/LanguageDomains.php index 8e38a95..b800fb4 100644 --- a/core/modules/language/src/Plugin/migrate/process/LanguageDomains.php +++ b/core/modules/language/src/Plugin/migrate/process/LanguageDomains.php @@ -21,21 +21,20 @@ class LanguageDomains extends ArrayBuild { * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - if ($row->hasSourceProperty('negotiation')) { - // Check if domain negotiation is used (LANGUAGE_NEGOTIATION_DOMAIN = 3). - if ($row->getSourceProperty('negotiation') == '3') { - global $base_url; + if ($row->getSourceProperty('domain_negotiation')) { + global $base_url; - foreach ($value as $old_key => $old_value) { - if (empty($old_value['domain'])) { - // The default language domain might be empty. - // If it is, use the current domain. - $value[$old_key]['domain'] = parse_url($base_url, PHP_URL_HOST); - } - else { - // Only keep the host part of the domain. - $value[$old_key]['domain'] = parse_url($old_value['domain'], PHP_URL_HOST); - } + foreach ($value as $old_key => $old_value) { + if (empty($old_value['domain'])) { + // The default language domain might be empty. + // If it is, use the current domain. + $value[$old_key]['domain'] = parse_url($base_url, PHP_URL_HOST); + } + else { + // Ensure we have a protocol when checking for the hostname. + $domain = 'http://' . str_replace(['http://', 'https://'], '', $old_value['domain']); + // Only keep the host part of the domain. + $value[$old_key]['domain'] = parse_url($domain, PHP_URL_HOST); } } } diff --git a/core/modules/language/src/Plugin/migrate/source/Language.php b/core/modules/language/src/Plugin/migrate/source/Language.php index 236d2fe..8543a94 100644 --- a/core/modules/language/src/Plugin/migrate/source/Language.php +++ b/core/modules/language/src/Plugin/migrate/source/Language.php @@ -60,12 +60,14 @@ public function prepareRow(Row $row) { $row->setSourceProperty('languages', $languages); } - if (!empty($this->configuration['negotiation'])) { - // Get the language negotiation method. - // We need it to find out if domain negotiation is used and thus fill in - // the default language domain, which may be empty. - $negotiation = $this->variableGet('language_negotiation', 0); - $row->setSourceProperty('negotiation', $negotiation); + if (!empty($this->configuration['domain_negotiation'])) { + // Check if domain negotiation is used to be able to fill in the default + // language domain, which may be empty. In D6, domain negotiation is used + // when the 'language_negotiation' variable is set to '3', and in D7, when + // the 'locale_language_negotiation_url_part' variable is set to '1'. + if ($this->variableGet('language_negotiation', 0) == 3 || $this->variableGet('locale_language_negotiation_url_part', 0) == 1) { + $row->setSourceProperty('domain_negotiation', TRUE); + } } return parent::prepareRow($row); diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageNegotiationSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageNegotiationSettingsTest.php index 7e60e25..0e74f49 100644 --- a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageNegotiationSettingsTest.php +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageNegotiationSettingsTest.php @@ -24,7 +24,7 @@ public function testLanguageNegotiationWithDefaultPathPrefix() { $this->executeMigrations([ 'language', 'd6_language_negotiation_settings', - 'd6_language_prefixes_and_domains', + 'language_prefixes_and_domains', 'd6_language_types', ]); @@ -63,7 +63,7 @@ public function testLanguageNegotiationWithNoNegotiation() { $this->executeMigrations([ 'language', 'd6_language_negotiation_settings', - 'd6_language_prefixes_and_domains', + 'language_prefixes_and_domains', 'd6_language_types', ]); @@ -95,7 +95,7 @@ public function testLanguageNegotiationWithPathPrefix() { $this->executeMigrations([ 'language', 'd6_language_negotiation_settings', - 'd6_language_prefixes_and_domains', + 'language_prefixes_and_domains', 'd6_language_types', ]); @@ -136,7 +136,7 @@ public function testLanguageNegotiationWithDomain() { $this->executeMigrations([ 'language', 'd6_language_negotiation_settings', - 'd6_language_prefixes_and_domains', + 'language_prefixes_and_domains', 'd6_language_types', ]); diff --git a/core/modules/language/tests/src/Unit/process/LanguageDomainsTest.php b/core/modules/language/tests/src/Unit/process/LanguageDomainsTest.php new file mode 100644 index 0000000..720f02b --- /dev/null +++ b/core/modules/language/tests/src/Unit/process/LanguageDomainsTest.php @@ -0,0 +1,59 @@ + 'language', + 'value' => 'domain', + ]; + $this->plugin = new LanguageDomains($configuration, 'map', []); + parent::setUp(); + + // The language_domains plugin calls getSourceProperty() to check if domain + // negotiation is used. If it is the values will be processed so we need it + // to return TRUE to be able to test the process. + $this->row->expects($this->once()) + ->method('getSourceProperty') + ->will($this->returnValue(TRUE)); + + // The language_domains plugin use $base_url to fill empty domains. + global $base_url; + $base_url = 'http://example.com'; + } + + public function testTransform() { + $source = [ + ['language' => 'en', 'domain' => ''], + ['language' => 'fr', 'domain' => 'fr.example.com'], + ['language' => 'es', 'domain' => 'http://es.example.com'], + ['language' => 'hu', 'domain' => 'https://hu.example.com'], + ]; + $expected = [ + 'en' => 'example.com', + 'fr' => 'fr.example.com', + 'es' => 'es.example.com', + 'hu' => 'hu.example.com', + ]; + $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame($value, $expected); + } + +} diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index 76e7c3e..b9d3ad3 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -286,7 +286,7 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'locale', 'destination_module' => 'language', ], - 'd6_language_prefixes_and_domains' => [ + 'language_prefixes_and_domains' => [ 'source_module' => 'locale', 'destination_module' => 'language', ],