VoyagerRoutes.php in GraphQL 8.3
Namespace
Drupal\graphql\RoutingFile
src/Routing/VoyagerRoutes.phpView source
<?php
namespace Drupal\graphql\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\graphql\Plugin\SchemaPluginManager;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* Registers graphql voyager routes for all schemas.
*/
class VoyagerRoutes extends RouteSubscriberBase {
/**
* The graphql schema plugin manager.
*
* @var \Drupal\graphql\Plugin\SchemaPluginManager
*/
protected $schemaManager;
/**
* VoyagerRoutes constructor.
*
* @param \Drupal\graphql\Plugin\SchemaPluginManager $schemaManager
* The graphql schema plugin manager.
*/
public function __construct(SchemaPluginManager $schemaManager) {
$this->schemaManager = $schemaManager;
}
/**
* Alters existing routes for a specific collection.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection for adding routes.
*/
protected function alterRoutes(RouteCollection $collection) {
$routes = new RouteCollection();
foreach ($this->schemaManager
->getDefinitions() as $key => $definition) {
$routes
->add("graphql.voyager.{$key}", new Route("{$definition['path']}/voyager", [
'schema' => $key,
'_controller' => '\\Drupal\\graphql\\Controller\\VoyagerController::viewVoyager',
'_title' => 'GraphQL Voyager',
], [
'_permission' => 'use graphql voyager',
], [
'_admin_route' => 'TRUE',
]));
}
$collection
->addCollection($routes);
}
}
Classes
Name | Description |
---|---|
VoyagerRoutes | Registers graphql voyager routes for all schemas. |