Skip to content
Snippets Groups Projects
Verified Commit c0199541 authored by Dave Long's avatar Dave Long
Browse files

Revert "Issue #3424720 by vidorado, douggreen, immaculatexavier, smustgrave,...

Revert "Issue #3424720 by vidorado, douggreen, immaculatexavier, smustgrave, uri_frazier: LanguageNegotiationUrl unnecessarily adds domain to outbound URL's"

This reverts commit c92b8429.
parent e12a2357
Branches
No related tags found
No related merge requests found
Pipeline #489106 passed
Pipeline: drupal

#489107

    ......@@ -345,7 +345,9 @@ public function testBlockPlacementIndicator(): void {
    // Removing a block will remove the block placement indicator.
    $this->clickLink('Remove');
    $this->submitForm([], 'Remove');
    $this->assertSession()->addressEquals('admin/structure/block/list/stark');
    // @todo https://www.drupal.org/project/drupal/issues/2980527 this should be
    // 'admin/structure/block/list/stark' but there is a bug.
    $this->assertSession()->addressEquals('admin/structure/block');
    }
    /**
    ......
    ......@@ -152,11 +152,6 @@ public function processOutbound($path, &$options = [], ?Request $request = NULL,
    elseif ($config['source'] == LanguageNegotiationUrl::CONFIG_DOMAIN) {
    if (is_object($options['language']) && !empty($config['domains'][$options['language']->getId()])) {
    // Check if the base URLs match, return early if they do.
    if (isset($options['base_url']) && $request && $request->getHost() === parse_url($options['base_url'], PHP_URL_HOST)) {
    return $path;
    }
    // Save the original base URL. If it contains a port, we need to
    // retain it below.
    if (!empty($options['base_url'])) {
    ......@@ -164,37 +159,34 @@ public function processOutbound($path, &$options = [], ?Request $request = NULL,
    $normalized_base_url = str_replace(['https://', 'http://'], '', $options['base_url']);
    }
    // Ask for an absolute URL with our modified base URL only if the domain
    // is different from the current request domain.
    if ($request && $request->getHost() !== $config['domains'][$options['language']->getId()]) {
    $options['absolute'] = TRUE;
    $options['base_url'] = $url_scheme . '://' . $config['domains'][$options['language']->getId()];
    // In case either the original base URL or the HTTP host contains a
    // port, retain it.
    if (isset($normalized_base_url) && str_contains($normalized_base_url, ':')) {
    [, $port] = explode(':', $normalized_base_url);
    $options['base_url'] .= ':' . $port;
    }
    elseif (($url_scheme == 'http' && $port != 80) || ($url_scheme == 'https' && $port != 443)) {
    $options['base_url'] .= ':' . $port;
    }
    // Ask for an absolute URL with our modified base URL.
    $options['absolute'] = TRUE;
    $options['base_url'] = $url_scheme . '://' . $config['domains'][$options['language']->getId()];
    if (isset($options['https'])) {
    if ($options['https'] === TRUE) {
    $options['base_url'] = str_replace('http://', 'https://', $options['base_url']);
    }
    elseif ($options['https'] === FALSE) {
    $options['base_url'] = str_replace('https://', 'http://', $options['base_url']);
    }
    }
    // In case either the original base URL or the HTTP host contains a
    // port, retain it.
    if (isset($normalized_base_url) && str_contains($normalized_base_url, ':')) {
    [, $port] = explode(':', $normalized_base_url);
    $options['base_url'] .= ':' . $port;
    }
    elseif (($url_scheme == 'http' && $port != 80) || ($url_scheme == 'https' && $port != 443)) {
    $options['base_url'] .= ':' . $port;
    }
    // Add Drupal's subfolder from the base_path if there is one.
    $options['base_url'] .= rtrim(base_path(), '/');
    if ($bubbleable_metadata) {
    $bubbleable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
    if (isset($options['https'])) {
    if ($options['https'] === TRUE) {
    $options['base_url'] = str_replace('http://', 'https://', $options['base_url']);
    }
    elseif ($options['https'] === FALSE) {
    $options['base_url'] = str_replace('https://', 'http://', $options['base_url']);
    }
    }
    // Add Drupal's subfolder from the base_path if there is one.
    $options['base_url'] .= rtrim(base_path(), '/');
    if ($bubbleable_metadata) {
    $bubbleable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
    }
    }
    }
    return $path;
    ......
    ......@@ -322,51 +322,6 @@ public static function providerTestDomain() {
    return $domain_configuration;
    }
    /**
    * Tests path outbound processing correctly setting relative/absolute paths.
    */
    public function testProcessOutboundOutputsRelativePathsForSameDomain(): void {
    $this->languageManager->expects($this->any())
    ->method('getCurrentLanguage')
    ->willReturn($this->languages['en']);
    $config = $this->getConfigFactoryStub([
    'language.negotiation' => [
    'url' => [
    'source' => LanguageNegotiationUrl::CONFIG_DOMAIN,
    'domains' => [
    'de' => 'example.de',
    'en' => 'example.com',
    ],
    ],
    ],
    ]);
    $request = Request::create('', 'GET', [], [], [], ['HTTP_HOST' => 'example.com']);
    $method = new LanguageNegotiationUrl();
    $method->setLanguageManager($this->languageManager);
    $method->setConfig($config);
    $method->setCurrentUser($this->user);
    // Check relative paths are used when the language
    // is the current language.
    $options = [
    'language' => $this->languages['en'],
    ];
    $method->processOutbound('foo', $options, $request);
    // $options['absolute'] not set or null equals to FALSE.
    $this->assertFalse($options['absolute'] ?? FALSE);
    // Check absolute paths are used when the language
    // is not the current language.
    $options = [
    'language' => $this->languages['de'],
    ];
    $method->processOutbound('foo', $options, $request);
    $this->assertTrue($options['absolute']);
    }
    }
    // @todo Remove as part of https://www.drupal.org/node/2481833.
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment