diff --git a/core/core.services.yml b/core/core.services.yml index 064a13ad..dfaa6340 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1357,7 +1357,7 @@ services: tags: - { name: path_processor_inbound, priority: 200 } - { name: path_processor_outbound, priority: 200 } - arguments: ['@config.factory'] + arguments: ['@config.factory', '@path_alias.manager'] route_processor_current: class: Drupal\Core\RouteProcessor\RouteProcessorCurrent arguments: ['@current_route_match'] diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php index 8045dd37..dd5a91e5 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php @@ -4,6 +4,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\Path\AliasManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -21,14 +22,22 @@ class PathProcessorFront implements InboundPathProcessorInterface, OutboundPathP */ protected $config; + /** + * @var \Drupal\Core\Path\AliasManagerInterface + */ + protected $alias_manager; + /** * Constructs a PathProcessorFront object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config * A config factory for retrieving the site front page configuration. + * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager + * The alias manager */ - public function __construct(ConfigFactoryInterface $config) { + public function __construct(ConfigFactoryInterface $config, AliasManagerInterface $alias_manager) { $this->config = $config; + $this->alias_manager = $alias_manager; } /** @@ -60,6 +69,22 @@ public function processInbound($path, Request $request) { * {@inheritdoc} */ public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) { + // Get the path or alias for the front page. + $front = $this->config->get('system.site')->get('page.front'); + $langcode = !empty($options['language']) ? $options['language']->getId() : NULL; + + // Get path and alias for the configured frontpage setting + $front_path = $this->alias_manager->getPathByAlias($front, $langcode); + $front_alias = $this->alias_manager->getAliasByPath($front, $langcode); + + // Replace the path and alias with default frontpage path + if (!empty($front_path) && $path === $front_path) { + $path = '/'; + } + if (!empty($front_alias) && $path === $front_alias) { + $path = '/'; + } + // The special path '' links to the default front page. if ($path === '/') { $path = '/';