You are here

function login_destination_link_alter in Login Destination 8

Same name and namespace in other branches
  1. 8.2 login_destination.module \login_destination_link_alter()

Implements hook_link_alter().

File

./login_destination.module, line 127
Control where users are directed to, once they login, register or logout.

Code

function login_destination_link_alter(&$variables) {
  $routes = [
    'user.login',
    'user.logout',
  ];

  /* @var Drupal\Core\Url $url */
  $url = $variables['url'];
  if ($url
    ->isRouted() && in_array($url
    ->getRouteName(), $routes)) {

    // Get current path.
    $current = \Drupal::service('path.current')
      ->getPath();
    $variables['options']['query']['current'] = $current;
  }
}