diff -u b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php --- b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -58,16 +58,9 @@ * \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL). * - 'https': Whether this URL should point to a secure location. If not * defined, the current scheme is used, so the user stays on HTTP or HTTPS -<<<<<<< HEAD * respectively. TRUE enforces HTTPS and FALSE enforces HTTP. - * - 'base_url': Only used internally, to modify the base URL when a language - * dependent URL requires so. -======= - * respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can - * only be enforced when the variable 'https' is set to TRUE. * - 'base_url': Only used internally by a path processor, for example, to * modify the base URL when a language dependent URL requires so. ->>>>>>> Docblock update. * - 'prefix': Only used internally, to modify the path when a language * dependent URL requires so. * - 'script': Added to the URL between the base path and the path prefix. only in patch2: unchanged: --- a/core/modules/language/src/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php @@ -7,7 +7,10 @@ namespace Drupal\language\Tests; +use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Routing\UrlGenerator; use Drupal\simpletest\WebTestBase; /** @@ -159,6 +162,72 @@ protected function doTestLanguageBlockAnonymous($block_label) { } /** + * Test languge switcher links for domain based negotiation + */ + + function testLanguageBlockWithDomain() { + global $base_url; + + // Get the current host URI we're running on. + $base_url_host = parse_url($base_url, PHP_URL_HOST); + + // Add the Italian language. + ConfigurableLanguage::createFromLangcode('it')->save(); + + $languages = $this->container->get('language_manager')->getLanguages(); + + // Enable browser and URL language detection. + $edit = array( + 'language_interface[enabled][language-url]' => TRUE, + 'language_interface[weight][language-url]' => -10, + ); + $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + + // Do not allow blank domain. + $edit = array( + 'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN, + 'domain[en]' => '', + ); + $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration')); + $this->assertText('The domain may not be left blank for English', 'The form does not allow blank domains.'); + $this->rebuildContainer(); + + // Change the domain for the Italian language. + $edit = array( + 'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN, + 'domain[en]' => $base_url_host, + 'domain[it]' => 'it.example.com', + ); + $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration')); + $this->assertText('The configuration options have been saved', 'Domain configuration is saved.'); + $this->rebuildContainer(); + + // Enable the language switcher block. + $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array('id' => 'test_language_block')); + + $this->drupalGet(''); + + /** @var UrlGenerator $generator */ + $generator = $this->container->get('url_generator'); + + // Verfify the English URL is correct + list($english_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array( + ':id' => 'block-test-language-block', + ':hreflang' => 'en', + )); + $english_url = $generator->generateFromPath('user/2', array('language' => $languages['en'])); + $this->assertEqual($english_url, (string) $english_link['href']); + + // Verfify the Italian URL is correct + list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', array( + ':id' => 'block-test-language-block', + ':hreflang' => 'it', + )); + $italian_url = $generator->generateFromPath('user/2', array('language' => $languages['it'])); + $this->assertEqual($italian_url, (string) $italian_link['href']); + } + + /** * Test active class on links when switching languages. */ function testLanguageLinkActiveClass() {