public function GlobalredirectSubscriber::globalredirectNormalizeAliases in Global Redirect 8
Normalizes the path aliases.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event:
File
- src/
EventSubscriber/ GlobalredirectSubscriber.php, line 166 - Contains \Drupal\globalredirect\EventSubscriber\GlobalredirectSubscriber.
Class
- GlobalredirectSubscriber
- KernelEvents::REQUEST subscriber for redirecting q=path/to/page requests.
Namespace
Drupal\globalredirect\EventSubscriberCode
public function globalredirectNormalizeAliases(GetResponseEvent $event) {
if ($event
->getRequestType() != HttpKernelInterface::MASTER_REQUEST || !$this->config
->get('normalize_aliases') || !($path = trim($event
->getRequest()
->getPathInfo(), '/'))) {
return;
}
$system_path = $this->aliasManager
->getPathByAlias($path);
$alias = $this->aliasManager
->getAliasByPath($system_path, $this->languageManager
->getCurrentLanguage()
->getId());
// If the alias defined in the system is not the same as the one via which
// the page has been accessed do a redirect to the one defined in the
// system.
if ($alias != $path) {
if ($url = \Drupal::pathValidator()
->getUrlIfValid($alias)) {
$this
->setResponse($event, $url);
}
}
}