protected function GlobalredirectSubscriber::setResponse in Global Redirect 8
Prior to set the response it check if we can redirect.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The event object.
\Drupal\Core\Url $url: The Url where we want to redirect.
4 calls to GlobalredirectSubscriber::setResponse()
- GlobalredirectSubscriber::globalredirectDeslash in src/
EventSubscriber/ GlobalredirectSubscriber.php - Detects a url with an ending slash (/) and removes it.
- GlobalredirectSubscriber::globalredirectForum in src/
EventSubscriber/ GlobalredirectSubscriber.php - Redirects forum taxonomy terms to correct forum path.
- GlobalredirectSubscriber::globalredirectFrontPage in src/
EventSubscriber/ GlobalredirectSubscriber.php - Redirects any path that is set as front page to the site root.
- GlobalredirectSubscriber::globalredirectNormalizeAliases in src/
EventSubscriber/ GlobalredirectSubscriber.php - Normalizes the path aliases.
File
- src/
EventSubscriber/ GlobalredirectSubscriber.php, line 212 - Contains \Drupal\globalredirect\EventSubscriber\GlobalredirectSubscriber.
Class
- GlobalredirectSubscriber
- KernelEvents::REQUEST subscriber for redirecting q=path/to/page requests.
Namespace
Drupal\globalredirect\EventSubscriberCode
protected function setResponse(GetResponseEvent $event, Url $url) {
$request = $event
->getRequest();
$this->context
->fromRequest($request);
parse_str($request
->getQueryString(), $query);
$url
->setOption('query', $query);
$url
->setAbsolute(TRUE);
// We can only check access for routed URLs.
if (!$url
->isRouted() || $this->redirectChecker
->canRedirect($url
->getRouteName(), $request)) {
// Add the 'rendered' cache tag, so that we can invalidate all responses
// when settings are changed.
$headers = [
'X-Drupal-Cache-Tags' => 'rendered',
];
$event
->setResponse(new RedirectResponse($url
->toString(), 301, $headers));
}
}