You are here

public function UserController::logout in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/src/Controller/UserController.php \Drupal\user\Controller\UserController::logout()
  2. 9 core/modules/user/src/Controller/UserController.php \Drupal\user\Controller\UserController::logout()

Logs the current user out.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirection to home page.

1 string reference to 'UserController::logout'
user.routing.yml in core/modules/user/user.routing.yml
core/modules/user/user.routing.yml

File

core/modules/user/src/Controller/UserController.php, line 317

Class

UserController
Controller routines for user routes.

Namespace

Drupal\user\Controller

Code

public function logout() {
  if ($this
    ->currentUser()
    ->isAuthenticated()) {
    user_logout();
  }
  return $this
    ->redirect('<front>');
}