You are here

function path_redirect_check_alias_changed in Path redirect 6

Creates a redirect if an URL alias is being changed.

Parameters

$path: The base (normal) path.

$new_alias: The new alias for the path.

$language: The language of the alias being created.

Return value

TRUE if a redirect was created, or FALSE otherwise.

1 call to path_redirect_check_alias_changed()
path_redirect_nodeapi in ./path_redirect.module
Implements hook_nodeapi().

File

./path_redirect.module, line 269

Code

function path_redirect_check_alias_changed($path, $new_alias, $language = '') {
  if (!variable_get('path_redirect_auto_redirect', 1) || empty($new_alias)) {
    return FALSE;
  }
  $old_alias = drupal_get_path_alias($path, $language);
  if ($old_alias != $path && $old_alias != $new_alias) {

    // If the user is manually changing the path alias, add a redirect from the old alias to the node.
    $redirect = array(
      'source' => $old_alias,
      'redirect' => $path,
    );
    path_redirect_save($redirect);
    return $redirect;
  }
}