public function UserSwitchController::switchbackuser in User Switch 8
Switch back to original user.
1 string reference to 'UserSwitchController::switchbackuser'
File
- src/
Controller/ UserSwitchController.php, line 108
Class
- UserSwitchController
- Provides route responses for the Example module.
Namespace
Drupal\userswitch\ControllerCode
public function switchbackuser() {
// Store current user name for messages.
$account_name = $this->currentUser
->getDisplayName();
$get_uid = $this->userswitch
->getUserId();
if ($get_uid) {
if ($this->userswitch
->switchUserBack()) {
$message = $this
->t('Switch account as @user.', [
'@user' => $account_name,
]);
$this->messenger
->addMessage($message);
}
else {
$message = $this
->t('Error trying as @user.', [
'@user,' => $account_name,
]);
$this->messenger
->addMessage($message, $this->messenger::TYPE_ERROR);
}
$url = Url::fromRoute('entity.user.canonical', [
'user' => $get_uid,
])
->toString();
}
else {
$url = Url::fromRoute('user.admin_index');
}
$response = new RedirectResponse($url);
$response
->send();
return new Response();
}