You are here

function helper_url_outbound_alter in Helper 7

Implements hook_url_outbound_alter().

Rewrite links to the login/register pages to include the current page so the user is redirected back to their original page.

File

./helper.module, line 195

Code

function helper_url_outbound_alter(&$path, &$options, $original_path) {
  $paths =& drupal_static(__FUNCTION__);
  if (!isset($paths)) {
    $paths = array();
    if (!helper_is_tweak_enabled('login_destination')) {
      $paths = FALSE;
    }
    elseif (user_is_anonymous()) {

      // These only should get destinations if the user is anonymous.
      $paths = array(
        'user',
        'user/login',
        'user/register',
        'user/password',
      );
    }
    if (!empty($paths)) {
      $paths = array_flip($paths);
    }
  }
  if (!empty($paths) && isset($paths[$path]) && !isset($options['query']['destination'])) {

    // Only add destination if we already have a destination path, or the
    // current path does not match the paths we want to add this too.
    if (isset($_GET['destination']) || !isset($paths[$_GET['q']])) {
      $options['query'] += drupal_get_destination();
    }
  }
}