locale_url_outbound_alter

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 locale_url_outbound_alter(&$path, &$options, $original_path)

Implements hook_url_outbound_alter().

Rewrite outbound URLs with language based prefixes.

Code

modules/locale/locale.module, line 985

<?php
function locale_url_outbound_alter(&$path, &$options, $original_path) {
  // Only modify internal URLs.
  if (!$options['external'] && drupal_multilingual()) {
    static $drupal_static_fast;
    if (!isset($drupal_static_fast)) {
      $drupal_static_fast['callbacks'] = &drupal_static(__FUNCTION__);
    }
    $callbacks = &$drupal_static_fast['callbacks'];

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

      foreach (language_types_configurable() as $type) {
        // Get url rewriter callbacks only from enabled language providers.
        $negotiation = variable_get("language_negotiation_$type", array());

        foreach ($negotiation as $id => $provider) {
          if (isset($provider['file'])) {
            require_once DRUPAL_ROOT . '/' . $provider['file'];
          }

          // Avoid duplicate callback entries.
          if (isset($provider['callbacks']['url_rewrite'])) {
            $callbacks[$provider['callbacks']['url_rewrite']] = NULL;
          }
        }
      }

      $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']);
    }
  }
}
?>