function language_url_rewrite_url

Rewrite URLs for the URL language negotiation method.

6 string references to 'language_url_rewrite_url'
LanguageUrlRewritingTest::setUp in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
Sets up a Drupal site for running functional and integration tests.
LanguageUrlRewritingTest::testDomainNameNegotiationPort in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
Check URL rewriting when using a domain name and a non-standard port.
language_language_negotiation_info in drupal/core/modules/language/language.module
Implements hook_language_negotiation_info().
locale_update_8007 in drupal/core/modules/locale/locale.install
Convert language_negotiation_* variables to use the new callbacks.
PathLanguageTest::testAliasTranslation in drupal/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php
Test alias functionality through the admin interfaces.

... See full list

File

drupal/core/modules/language/language.negotiation.inc, line 427
Language negotiation functions.

Code

function language_url_rewrite_url(&$path, &$options) {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['languages'] =& drupal_static(__FUNCTION__);
  }
  $languages =& $drupal_static_fast['languages'];
  if (!isset($languages)) {
    $languages = language_list();
    $languages = array_flip(array_keys($languages));
  }

  // Language can be passed as an option, or we go for current URL language.
  if (!isset($options['language'])) {
    $language_url = language(LANGUAGE_TYPE_URL);
    $options['language'] = $language_url;
  }
  elseif (is_object($options['language']) && !isset($languages[$options['language']->langcode])) {
    unset($options['language']);
    return;
  }
  if (isset($options['language'])) {
    switch (config('language.negotiation')
      ->get('url.source')) {
      case LANGUAGE_NEGOTIATION_URL_DOMAIN:
        $domains = language_negotiation_url_domains();
        if (is_object($options['language']) && !empty($domains[$options['language']->langcode])) {
          global $is_https;

          // Save the original base URL. If it contains a port, we need to
          // retain it below.
          if (!empty($options['base_url'])) {

            // The colon in the URL scheme messes up the port checking below.
            $normalized_base_url = str_replace(array(
              'https://',
              'http://',
            ), '', $options['base_url']);
          }

          // Ask for an absolute URL with our modified base URL.
          $url_scheme = $is_https ? 'https://' : 'http://';
          $options['absolute'] = TRUE;
          $options['base_url'] = $url_scheme . $domains[$options['language']->langcode];

          // In case either the original base URL or the HTTP host contains a
          // port, retain it.
          $http_host = $_SERVER['HTTP_HOST'];
          if (isset($normalized_base_url) && strpos($normalized_base_url, ':') !== FALSE) {
            list($host, $port) = explode(':', $normalized_base_url);
            $options['base_url'] .= ':' . $port;
          }
          elseif (strpos($http_host, ':') !== FALSE) {
            list($host, $port) = explode(':', $http_host);
            $options['base_url'] .= ':' . $port;
          }
          if (isset($options['https']) && variable_get('https', FALSE)) {
            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']);
            }
          }
        }
        break;
      case LANGUAGE_NEGOTIATION_URL_PREFIX:
        $prefixes = language_negotiation_url_prefixes();
        if (is_object($options['language']) && !empty($prefixes[$options['language']->langcode])) {
          $options['prefix'] = $prefixes[$options['language']->langcode] . '/';
        }
        break;
    }
  }
}