RouteLoad.php in GraphQL 8.4
File
src/Plugin/GraphQL/DataProducer/Routing/RouteLoad.php
View source
<?php
namespace Drupal\graphql\Plugin\GraphQL\DataProducer\Routing;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\redirect\RedirectRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RouteLoad extends DataProducerPluginBase implements ContainerFactoryPluginInterface {
protected $pathValidator;
protected $redirectRepository;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('path.validator'), $container
->get('redirect.repository', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
public function __construct(array $configuration, $pluginId, $pluginDefinition, PathValidatorInterface $pathValidator, ?RedirectRepository $redirectRepository = NULL) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->pathValidator = $pathValidator;
$this->redirectRepository = $redirectRepository;
}
public function resolve($path, RefinableCacheableDependencyInterface $metadata) {
if ($this->redirectRepository) {
$redirect = $this->redirectRepository
->findMatchingRedirect($path, []);
if ($redirect) {
return $redirect
->getRedirectUrl();
}
}
if (($url = $this->pathValidator
->getUrlIfValidWithoutAccessCheck($path)) && $url
->isRouted() && $url
->access()) {
return $url;
}
$metadata
->addCacheTags([
'4xx-response',
]);
return NULL;
}
}