1 locale.module locale_url_outbound_alter(&$path, &$options, $original_path)

Implements hook_url_outbound_alter().

Rewrite outbound URLs with language based prefixes.

File

core/modules/locale/locale.module, line 890
Add language handling functionality and enables the translation of the user interface to languages other than English.

Code

function locale_url_outbound_alter(&$path, &$options, $original_path) {
  // Only modify internal URLs.
  if (!$options['external'] && language_multilingual()) {
    static $backdrop_static_fast;
    if (!isset($backdrop_static_fast)) {
      $backdrop_static_fast['callbacks'] = &backdrop_static(__FUNCTION__);
    }
    $callbacks = &$backdrop_static_fast['callbacks'];

    if (!isset($callbacks)) {
      $callbacks = array();
      include_once BACKDROP_ROOT . '/core/includes/language.inc';

      $negotiation_info = language_negotiation_info();
      foreach (language_types_get_configurable() as $type) {
        // Get URL rewriter callbacks only from enabled language providers.
        $negotiation_providers = language_negotiation_order($type);
        foreach ($negotiation_providers as $id) {
          $provider = $negotiation_info[$id];
          if (isset($provider['callbacks']['url_rewrite'])) {
            if (isset($provider['file'])) {
              require_once BACKDROP_ROOT . '/' . $provider['file'];
            }
            // Avoid duplicate callback entries.
            $callbacks[$provider['callbacks']['url_rewrite']] = TRUE;
          }
        }
      }

      $callbacks = array_keys($callbacks);
    }

    foreach ($callbacks as $callback) {
      $callback($path, $options);
    }

    // No language dependent path allowed in this mode.
    if (empty($callbacks)) {
      unset($options['language']);
    }
  }
}