digitalist.global // October 05 2016

Redirect user after logout programmatically

This is how you use the hook_user_logout to implement a redirect in Drupal 8.

For implementing a redirect in Drupal 8, we can do it using the hook_user_logout()

/**
 * Implements hook_user_logout().
 */
function mymoduler_user_logout() {
  // we redirect to an external site
  $response = new RedirectResponse("https://www.google.se");
  $response->send();
  return $response;
}

Remember to include the library:

use \Symfony\Component\HttpFoundation\RedirectResponse;

More from digitalist.global