Skip to content
Snippets Groups Projects
Commit 77dbe358 authored by Michael Strelan's avatar Michael Strelan
Browse files

Attempt to make RequestPath work without path_alias

parent fb50edd8
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI
/**
* An alias manager to find the alias for the current system path.
*
* @var \Drupal\path_alias\AliasManagerInterface
* @var \Drupal\path_alias\AliasManagerInterface|null
*/
protected $aliasManager;
......@@ -67,7 +67,7 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI
* @param array $plugin_definition
* The plugin implementation definition.
*/
public function __construct(AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher, RequestStack $request_stack, CurrentPathStack $current_path, array $configuration, $plugin_id, array $plugin_definition) {
public function __construct(?AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher, RequestStack $request_stack, CurrentPathStack $current_path, array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->aliasManager = $alias_manager;
$this->pathMatcher = $path_matcher;
......@@ -80,7 +80,7 @@ public function __construct(AliasManagerInterface $alias_manager, PathMatcherInt
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$container->get('path_alias.manager'),
$container->has('path_alias.manager') ? $container->get('path_alias.manager') : NULL,
$container->get('path.matcher'),
$container->get('request_stack'),
$container->get('path.current'),
......@@ -164,7 +164,7 @@ public function evaluate() {
$path = $this->currentPath->getPath($request);
// Do not trim a trailing slash if that is the complete path.
$path = $path === '/' ? $path : rtrim($path, '/');
$path_alias = mb_strtolower($this->aliasManager->getAliasByPath($path));
$path_alias = $this->aliasManager === NULL ? $path : mb_strtolower($this->aliasManager->getAliasByPath($path));
return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment