Skip to content
Snippets Groups Projects

Issue #2948211: Front page redirects break the canonical link

@@ -31,6 +31,13 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface {
*/
protected $config;
/**
* Global configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $configMain;
/**
* The URL generator service.
*
@@ -73,6 +80,7 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface {
$this->pathMatcher = $path_matcher;
$this->redirectChecker = $redirect_checker;
$this->config = $config->get('redirect.settings');
$this->configMain = $config;
}
/**
@@ -103,7 +111,16 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface {
if ($this->redirectChecker->canRedirect($request)) {
// The "<current>" placeholder can be used for all routes except the front
// page because it's not a real route.
$route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>';
$current_path = $this->currentPath->getPath();
$front_uri = $this->configMain->get('system.site')->get('page.front');
$front_alias = $this->aliasManager->getAliasByPath($front_uri);
$current_alias = $this->aliasManager->getAliasByPath($current_path);
$isFrontPage = $this->pathMatcher->isFrontPage() || $front_alias === $current_alias;
$route_name = '<current>';
if ($isFrontPage) {
$route_name = '<front>';
}
// Explicitly replicate PathAliasSubscriber::onKernelController() to set
// the cache key.
Loading