|
3 | 3 | namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Routing; |
4 | 4 |
|
5 | 5 | use Drupal\Component\Utility\UrlHelper; |
| 6 | +use Drupal\Core\Path\PathValidatorInterface; |
| 7 | +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
6 | 8 | use Drupal\Core\Url; |
7 | 9 | use Drupal\graphql\GraphQL\Cache\CacheableValue; |
8 | 10 | use Drupal\graphql\GraphQL\Execution\ResolveContext; |
9 | 11 | use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; |
10 | 12 | use GraphQL\Type\Definition\ResolveInfo; |
| 13 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
11 | 14 |
|
12 | 15 | /** |
13 | 16 | * Retrieve a route object based on a path. |
|
23 | 26 | * } |
24 | 27 | * ) |
25 | 28 | */ |
26 | | -class Route extends FieldPluginBase { |
| 29 | +class Route extends FieldPluginBase implements ContainerFactoryPluginInterface { |
| 30 | + |
| 31 | + /** |
| 32 | + * The path validator service. |
| 33 | + * |
| 34 | + * @var \Drupal\Core\Path\PathValidatorInterface |
| 35 | + */ |
| 36 | + protected $pathValidator; |
| 37 | + |
| 38 | + /** |
| 39 | + * {@inheritdoc} |
| 40 | + */ |
| 41 | + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
| 42 | + return new static( |
| 43 | + $configuration, |
| 44 | + $plugin_id, |
| 45 | + $plugin_definition, |
| 46 | + $container->get('path.validator') |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Route constructor. |
| 52 | + * |
| 53 | + * @param array $configuration |
| 54 | + * The plugin configuration. |
| 55 | + * @param string $pluginId |
| 56 | + * The plugin id. |
| 57 | + * @param mixed $pluginDefinition |
| 58 | + * The plugin definition. |
| 59 | + * @param \Drupal\Core\Path\PathValidatorInterface $pathValidator |
| 60 | + * The path validator service. |
| 61 | + */ |
| 62 | + public function __construct(array $configuration, $pluginId, $pluginDefinition, PathValidatorInterface $pathValidator) { |
| 63 | + parent::__construct($configuration, $pluginId, $pluginDefinition); |
| 64 | + $this->pathValidator = $pathValidator; |
| 65 | + } |
27 | 66 |
|
28 | 67 | /** |
29 | 68 | * {@inheritdoc} |
30 | 69 | */ |
31 | 70 | public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
32 | | - if (UrlHelper::isExternal($args['path'])) { |
33 | | - yield Url::fromUri($args['path']); |
| 71 | + if (($url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($args['path'])) && $url->access()) { |
| 72 | + yield $url; |
34 | 73 | } |
35 | 74 | else { |
36 | | - $url = Url::fromUri("internal:{$args['path']}", ['routed_path' => $args['path']]); |
37 | | - if ($url->isRouted() && $url->access()) { |
38 | | - yield $url; |
39 | | - } |
40 | | - else { |
41 | | - yield (new CacheableValue(NULL))->addCacheTags(['4xx-response']); |
42 | | - } |
| 75 | + yield (new CacheableValue(NULL))->addCacheTags(['4xx-response']); |
43 | 76 | } |
44 | 77 | } |
45 | 78 |
|
|
0 commit comments