You are here

public function SwitchController::switchBack in Masquerade 8.2

Allows a user who is currently masquerading to become a new user.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirect response to previous page.

See also

this::getRedirectResponse()

1 string reference to 'SwitchController::switchBack'
masquerade.routing.yml in ./masquerade.routing.yml
masquerade.routing.yml

File

src/Controller/SwitchController.php, line 105

Class

SwitchController
Controller for switch and back to masquerade as user.

Namespace

Drupal\masquerade\Controller

Code

public function switchBack(Request $request) {

  // Store current user name for messages.
  $account_name = $this->currentUser
    ->getDisplayName();
  if ($this->masquerade
    ->switchBack()) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('You are no longer masquerading as @user.', [
      '@user' => $account_name,
    ]));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('Error trying unmasquerading as @user.', [
      '@user' => $account_name,
    ]));
  }
  return $this
    ->getRedirectResponse($request);
}