You are here

function login_destination_perform_redirect in Login Destination 8.2

Same name and namespace in other branches
  1. 8 login_destination.module \login_destination_perform_redirect()
  2. 7 login_destination.module \login_destination_perform_redirect()

Evaluate rules and perform redirect.

This function is intended to be used by external modules.

Parameters

string $trigger: Action of login destination rule.

\Drupal\Core\Session\AccountInterface $account: User Account.

3 calls to login_destination_perform_redirect()
login_destination_form_user_form_submit in ./login_destination.module
Submit handler for form 'user_form'.
login_destination_user_login in ./login_destination.module
Implements hook_user_login().
login_destination_user_logout in ./login_destination.module
Implements hook_user_logout().

File

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

Code

function login_destination_perform_redirect($trigger, AccountInterface $account) {

  /* @var Drupal\login_destination\LoginDestinationManager $service */
  $service = \Drupal::service('login_destination.manager');
  $destination = $service
    ->findDestination($trigger, $account);
  if ($destination) {

    // Check if it's a external URL.
    if (UrlHelper::isExternal($destination->destination_path)) {
      $response = new TrustedRedirectResponse($destination->destination_path);
      $response
        ->send();
    }
    $service
      ->prepareDestination($destination);
  }
}