SchemaOverviewController.php in GraphQL 8.3
File
src/Controller/SchemaOverviewController.php
View source
<?php
namespace Drupal\graphql\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\graphql\Plugin\SchemaPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SchemaOverviewController implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $schemaManager;
protected $moduleHandler;
public static function create(ContainerInterface $container) {
return new static($container
->get('module_handler'), $container
->get('plugin.manager.graphql.schema'));
}
public function __construct(ModuleHandlerInterface $moduleHandler, SchemaPluginManager $schemaManager) {
$this->schemaManager = $schemaManager;
$this->moduleHandler = $moduleHandler;
}
public function listSchemas() {
$table = [
'#type' => 'table',
'#header' => [
$this
->t('Schema'),
$this
->t('Provider'),
$this
->t('Operations'),
],
'#attributes' => [
'id' => 'graphql-schemas',
],
];
foreach ($this->schemaManager
->getDefinitions() as $key => $definition) {
$table["schema:{$key}"]['name'] = [
'#plain_text' => $definition['name'],
];
$table["schema:{$key}"]['provider'] = [
'#plain_text' => $this->moduleHandler
->getName($definition['provider']),
];
$table["schema:{$key}"]['operations'] = $this
->buildOperations($key, $definition);
}
return $table;
}
protected function buildOperations($pluginId, array $pluginDefinition) {
$build = [
'#type' => 'operations',
'#links' => $this
->getOperations($pluginId, $pluginDefinition),
];
return $build;
}
protected function getOperations($pluginId, $pluginDefinition) {
$operations = $this->moduleHandler
->invokeAll('graphql_schema_operations', [
$pluginId,
$pluginDefinition,
]);
$this->moduleHandler
->alter('graphql_schema_operations', $operations, $pluginId, $pluginDefinition);
uasort($operations, '\\Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $operations;
}
}