You are here

public function GlobalredirectSubscriber::globalredirectFrontPage in Global Redirect 8

Redirects any path that is set as front page to the site root.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event:

File

src/EventSubscriber/GlobalredirectSubscriber.php, line 146
Contains \Drupal\globalredirect\EventSubscriber\GlobalredirectSubscriber.

Class

GlobalredirectSubscriber
KernelEvents::REQUEST subscriber for redirecting q=path/to/page requests.

Namespace

Drupal\globalredirect\EventSubscriber

Code

public function globalredirectFrontPage(GetResponseEvent $event) {
  if (!$this->config
    ->get('frontpage_redirect') || $event
    ->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
    return;
  }
  $request = $event
    ->getRequest();
  $path = trim($request
    ->getPathInfo(), '/');

  // Redirect only if the current path is not the root and this is the front
  // page.
  if ($this
    ->isFrontPage($path)) {
    $this
      ->setResponse($event, Url::fromRoute('<front>'));
  }
}