You are here

public function GlobalredirectSubscriber::globalredirectForum in Global Redirect 8

Redirects forum taxonomy terms to correct forum path.

Parameters

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

File

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

Class

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

Namespace

Drupal\globalredirect\EventSubscriber

Code

public function globalredirectForum(GetResponseEvent $event) {
  $request = $event
    ->getRequest();
  if ($event
    ->getRequestType() != HttpKernelInterface::MASTER_REQUEST || !$this->config
    ->get('term_path_handler') || !$this->moduleHandler
    ->moduleExists('forum') || !preg_match('/taxonomy\\/term\\/([0-9]+)$/', $request
    ->getUri(), $matches)) {
    return;
  }
  $term = $this->entityManager
    ->getStorage('taxonomy_term')
    ->load($matches[1]);
  if (!empty($term) && $term
    ->url() != $request
    ->getPathInfo()) {
    $this
      ->setResponse($event, Url::fromUri('entity:taxonomy_term/' . $term
      ->id()));
  }
}