You can for example create a custom ViewsArgumentValidator and transform the given alias to the Node ID.
<?php
namespace Drupal\my_module\Plugin\views\argument_validator;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Validates whether an alias is a valid node alias and transform it to the nid.
*
* @ViewsArgumentValidator(
* id = "node_alias",
* title = @Translation("Node ID by alias")
* )
*/
class NodeAlias extends ArgumentValidatorPluginBase {
/**
* The alias manager.
*
* @var \Drupal\path_alias\AliasManagerInterface
*/
protected $aliasManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AliasManagerInterface $alias_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->aliasManager = $alias_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('path_alias.manager'),
);
}
/**
* {@inheritdoc}
*/
public function validateArgument($argument) {
// Prepend slash.
$argument = '/' . ltrim($argument, '/');
$path = $this->aliasManager->getPathByAlias($argument);
if (preg_match('/node\/(\d+)/', $path, $matches)) {
$this->argument->argument = $matches[1];
return TRUE;
}
return FALSE;
}
}
In the validateArgument function we are checking if an internal path for a node can be found with that alias and transform the given argument to the corresponding Node ID.
Add this file named NodeAlias.php to you custom module in src/Plugin/views/argument_validator directory and clear the cache.
After that, you can use the Content: Nid contextual filter and select in the "When the filter value is in the URL or a default is provided" section the new Validator Node ID by alias.