Drupal core expects only internal URL (node/123) in the page.front setting. See \Drupal\Core\Path\PathMatcher::isFrontPage
.
To be able to set page alias in the front page settings, I have created
a workaround. I made a replacement of the path.matcher
using an alias fallback:
mymodule/src/MymoduleServiceProvider.php:
<?php
namespace Drupal\mymodule;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Reference;
/**
* Modifies the path matcher service.
*/
class MymoduleServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
// Override the path matcher for the alias fallback.
$definition = $container->getDefinition('path.matcher');
$definition->setClass('Drupal\mymodule\AliasFallbackPathMatcher')
->addArgument(new Reference('path.alias_manager'));
}
}
mymodule/src/AliasFallbackPathMatcher.php:
<?php
namespace Drupal\mymodule;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Path\PathMatcher;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* The path matcher with alias fallback implementation.
*/
class AliasFallbackPathMatcher extends PathMatcher {
/**
* The alias manager.
*
* @var \Drupal\Core\Path\AliasManagerInterface
*/
protected $aliasManager;
/**
* Creates a new PathMatcher.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
* The alias manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, RouteMatchInterface $route_match, AliasManagerInterface $alias_manager) {
parent::__construct($config_factory, $route_match);
$this->aliasManager = $alias_manager;
}
/**
* {@inheritdoc}
*
* Support path alias for the front page path.
*/
protected function getFrontPagePath() {
if (!isset($this->frontPage)) {
$path = parent::getFrontPagePath();
$this->frontPage = $this->aliasManager->getPathByAlias($path);
}
return $this->frontPage;
}
}