You are here

function locale_url_outbound_alter in Drupal 7

Implements hook_url_outbound_alter().

Rewrite outbound URLs with language based prefixes.

3 string references to 'locale_url_outbound_alter'
LocaleUrlRewritingTest::setUp in modules/locale/locale.test
Sets up a Drupal site for running functional and integration tests.
PathLanguageTestCase::testAliasTranslation in modules/path/path.test
Test alias functionality through the admin interfaces.
TranslationTestCase::resetCaches in modules/translation/translation.test
Resets static caches to make the test code match the client-side behavior.

File

modules/locale/locale.module, line 1059
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'] && 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['callbacks']['url_rewrite'])) {
            if (isset($provider['file'])) {
              require_once DRUPAL_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']);
    }
  }
}