protected function SwitchController::getRedirectResponse in Masquerade 8.2
Returns redirect response to previous page.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse The redirect.
See also
\Drupal\Core\EventSubscriber\RedirectResponseSubscriber::checkRedirectUrl()
2 calls to SwitchController::getRedirectResponse()
- SwitchController::switchBack in src/
Controller/ SwitchController.php - Allows a user who is currently masquerading to become a new user.
- SwitchController::switchTo in src/
Controller/ SwitchController.php - Masquerades the current user as a given user.
File
- src/
Controller/ SwitchController.php, line 132
Class
- SwitchController
- Controller for switch and back to masquerade as user.
Namespace
Drupal\masquerade\ControllerCode
protected function getRedirectResponse(Request $request) {
if ($destination_path = $this->destination
->get()) {
// When Drupal is installed in a sub-directory, destination path have to
// cut off the baseUrl part.
$destination_path = preg_replace('/^' . preg_quote($request
->getBaseUrl(), '/') . '/', '', $destination_path);
// Try destination first.
$url = Url::createFromRequest(Request::create($destination_path));
}
elseif ($redirect_path = $request->server
->get('HTTP_REFERER')) {
// Parse referer to get route name if any.
$url = Url::createFromRequest(Request::create($redirect_path));
}
else {
// Fallback to front page if no referrer.
$url = Url::fromRoute('<front>');
}
// Check access for redirected url.
if (!$url
->access($this->currentUser)) {
// Fallback to front page redirect.
$url = Url::fromRoute('<front>');
}
$url = $url
->setAbsolute()
->toString();
if ($destination_path) {
// Override destination because it will take over response.
$request->query
->set('destination', $url);
$this->destination
->set($url);
}
return new RedirectResponse($url);
}