You are here

function path_alias_xt_url_outbound_alter in Extended Path Aliases 7

Implements hook_url_outbound_alter().

File

./path_alias_xt.module, line 126
Extended Path Aliases.

Code

function path_alias_xt_url_outbound_alter(&$path, array &$options, $original_path) {

  // This hook implementation gets called from url($path).
  // The path as passed to us by the function url(), which we may turn into
  // the aliased path or leave unchanged.
  // If $options['alias'] is set to TRUE, the path is assumed already to be
  // the correct path alias, and the alias is not looked up.
  // @see includes/common.inc::url()
  if (!empty($options['alias'])) {
    return;
  }
  if ($path == $original_path) {

    // This is always the case unless altered by another module implementing
    // this hook.
    $pattern = variable_get('path_alias_xt_regex_pattern', PATH_ALIAS_XT_DEFAULT_NODE_OR_USER_MATCH);
    if (preg_match($pattern, $path, $matches)) {
      if ($alias = drupal_lookup_path('alias', "{$matches[1]}/{$matches[2]}")) {
        $path = "{$alias}/{$matches[3]}";
      }
    }
  }
}