You are here

function redirect_url_inbound_alter in Redirect 7.2

Same name and namespace in other branches
  1. 7 redirect.module \redirect_url_inbound_alter()

Implements hook_url_inbound_alter().

File

./redirect.module, line 212

Code

function redirect_url_inbound_alter(&$path, $original_path, $path_language) {

  // If the current path global does not exist, then drupal_get_path_alias()
  // will fail. This condition only happens when $path is the front page.
  // @todo Remove when http://drupal.org/node/1329914 is fixed in core.
  if (empty($_GET['q'])) {
    $_GET['q'] = variable_get('site_frontpage', 'node');
    return;
  }

  // If the inbound path has been changed, then attempt to find a redirect
  // matching the original path and save it for processing later in
  // redirect_init(). For example, if the Sub-pathauto module changes the path
  // 'foo/redirect' to 'node/1/redirect', and there is a redirect enabled for
  // the path 'foo/redirect', then redirect_init() would normally fail since it
  // would not find a match.
  if ($path != $original_path && $original_path == current_path()) {
    $current_langcode = !empty($path_language) ? $path_language : $GLOBALS['language']->language;
    $current_query = drupal_get_query_parameters();
    if ($redirect = redirect_load_by_source($original_path, $current_langcode, $current_query)) {
      redirect_set_current_redirect($redirect);
    }
  }

  // Redirect to canonical URLs.
  // Commented out per https://www.drupal.org/node/2048137.

  //if ($path && variable_get('redirect_canonical', 1)) {

  //$alias = drupal_get_path_alias($path, $path_language);

  //if ($alias != $path && $alias != $original_path) {

  //return redirect_redirect(array('redirect' => $alias, 'type' => 'global'));

  //}

  // Redirect from default entity paths to the proper entity path.

  //if ($path_entity = redirect_load_entity_from_path($path)) {

  //  if ($uri = entity_uri($path_entity['entity_type'], $path_entity['entity'])) {
  //    if ($path != $uri['path']) {
  //      return redirect_redirect(array('redirect' => $uri['path'], 'redirect_options' => $uri['options'], 'type' => 'global'));
  //    }
  //  }

  //}

  //}
}