class Route in GraphQL 8.3
Retrieve a route object based on a path.
Plugin annotation
@GraphQLField(
id = "url_route",
secure = true,
name = "route",
description = @Translation("Loads a route by its path."),
type = "Url",
arguments = {
"path" = "String!"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase implements FieldPluginInterface uses ArgumentAwarePluginTrait, CacheablePluginTrait, DeprecatablePluginTrait, DescribablePluginTrait, TypedPluginTrait
- class \Drupal\graphql_core\Plugin\GraphQL\Fields\Routing\Route implements ContainerFactoryPluginInterface
- class \Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase implements FieldPluginInterface uses ArgumentAwarePluginTrait, CacheablePluginTrait, DeprecatablePluginTrait, DescribablePluginTrait, TypedPluginTrait
Expanded class hierarchy of Route
File
- modules/
graphql_core/ src/ Plugin/ GraphQL/ Fields/ Routing/ Route.php, line 29
Namespace
Drupal\graphql_core\Plugin\GraphQL\Fields\RoutingView source
class Route extends FieldPluginBase implements ContainerFactoryPluginInterface {
/**
* The path validator service.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
/**
* The language negotiator service.
*
* @var \Drupal\language\LanguageNegotiator
*/
protected $languageNegotiator;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* @var \Drupal\redirect\RedirectRepository
*/
protected $redirectRepository;
/**
* @var InboundPathProcessorInterface
*/
protected $pathProcessor;
/**
* {@inheritdoc}
*/
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('language_negotiator', ContainerInterface::NULL_ON_INVALID_REFERENCE), $container
->get('language_manager'), $container
->get('redirect.repository', ContainerInterface::NULL_ON_INVALID_REFERENCE), $container
->get('path_processor_manager'));
}
/**
* Route constructor.
*
* @param array $configuration
* The plugin configuration.
* @param string $pluginId
* The plugin id.
* @param mixed $pluginDefinition
* The plugin definition.
* @param \Drupal\Core\Path\PathValidatorInterface $pathValidator
* The path validator service.
* @param \Drupal\language\LanguageNegotiator|null $languageNegotiator
* The language negotiator.
* @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
* The language manager.
* @param \Drupal\redirect\RedirectRepository $redirectRepository
* The redirect repository, if redirect module is active.
* @param \Drupal\Core\PathProcessor\InboundPathProcessorInterface
* An inbound path processor, to clean paths before redirect lookups.
*/
public function __construct(array $configuration, $pluginId, $pluginDefinition, PathValidatorInterface $pathValidator, $languageNegotiator, $languageManager, $redirectRepository, $pathProcessor) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->redirectRepository = $redirectRepository;
$this->pathProcessor = $pathProcessor;
$this->pathValidator = $pathValidator;
$this->languageNegotiator = $languageNegotiator;
$this->languageManager = $languageManager;
}
/**
* {@inheritdoc}
*
* Execute routing in language context.
*
* Language context has to be inferred from the path prefix, but set before
* `resolveValues` is invoked.
*/
public function resolve($value, array $args, ResolveContext $context, ResolveInfo $info) {
// For now we just take the "url" negotiator into account.
if ($this->languageManager
->isMultilingual() && $this->languageNegotiator) {
if ($negotiator = $this->languageNegotiator
->getNegotiationMethodInstance('language-url')) {
$context
->setContext('language', $negotiator
->getLangcode(Request::create($args['path'])), $info);
}
else {
$context
->setContext('language', $this->languageManager
->getDefaultLanguage()
->getId(), $info);
}
}
return parent::resolve($value, $args, $context, $info);
}
/**
* {@inheritdoc}
*
* Route field is always language aware since it sets it's context from
* the prefix.
*/
protected function isLanguageAwareField() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
if ($this->redirectRepository) {
$currentLanguage = $this->languageManager
->getCurrentLanguage()
->getId();
$processedPath = $this->pathProcessor
->processInbound($args['path'], Request::create($args['path']));
if ($redirect = $this->redirectRepository
->findMatchingRedirect($processedPath, [], $currentLanguage)) {
(yield $redirect);
return;
}
}
if (($url = $this->pathValidator
->getUrlIfValidWithoutAccessCheck($args['path'])) && $url
->access()) {
(yield $url);
}
else {
(yield (new CacheableValue(NULL))
->addCacheTags([
'4xx-response',
]));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ArgumentAwarePluginTrait:: |
protected | function | Builds an argument's default value. | |
ArgumentAwarePluginTrait:: |
protected | function | Builds an argument's description. | |
ArgumentAwarePluginTrait:: |
protected | function | Builds the list of arguments. | |
ArgumentAwarePluginTrait:: |
protected | function | Builds an argument's type. | |
CacheablePluginTrait:: |
protected | function | ||
DeprecatablePluginTrait:: |
protected | function | ||
DescribablePluginTrait:: |
protected | function | ||
FieldPluginBase:: |
protected | property | Static cache for `isLanguageAwareField()` | |
FieldPluginBase:: |
protected | property | The language context service. | |
FieldPluginBase:: |
protected | property | The renderer service. | 1 |
FieldPluginBase:: |
public static | function |
Overrides FieldPluginInterface:: |
|
FieldPluginBase:: |
protected | function | Retrieve the list of cache dependencies for a given value and arguments. | 1 |
FieldPluginBase:: |
public | function |
Returns the plugin's type or field definition for the schema. Overrides FieldPluginInterface:: |
|
FieldPluginBase:: |
protected | function | Get the language context instance. | |
FieldPluginBase:: |
protected | function | Get the renderer service. | |
FieldPluginBase:: |
protected | function | ||
FieldPluginBase:: |
protected | function | Unwrap the resolved values. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
Route:: |
protected | property | The language manager. | |
Route:: |
protected | property | The language negotiator service. | |
Route:: |
protected | property | ||
Route:: |
protected | property | The path validator service. | |
Route:: |
protected | property | ||
Route:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Route:: |
protected | function |
Route field is always language aware since it sets it's context from
the prefix. Overrides FieldPluginBase:: |
|
Route:: |
public | function |
Execute routing in language context. Overrides FieldPluginBase:: |
|
Route:: |
public | function |
Retrieve the list of field values. Overrides FieldPluginBase:: |
|
Route:: |
public | function |
Route constructor. Overrides PluginBase:: |
|
TypedPluginTrait:: |
protected | function |