class SchemaOverviewController in GraphQL 8.3
Hierarchy
- class \Drupal\graphql\Controller\SchemaOverviewController implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of SchemaOverviewController
File
- src/
Controller/ SchemaOverviewController.php, line 11
Namespace
Drupal\graphql\ControllerView source
class SchemaOverviewController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The schema plugin manager service.
*
* @var \Drupal\graphql\Plugin\SchemaPluginManager
*/
protected $schemaManager;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('module_handler'), $container
->get('plugin.manager.graphql.schema'));
}
/**
* SchemaOverviewController constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler srevice.
* @param \Drupal\graphql\Plugin\SchemaPluginManager $schemaManager
* The schema plugin manager service.
*/
public function __construct(ModuleHandlerInterface $moduleHandler, SchemaPluginManager $schemaManager) {
$this->schemaManager = $schemaManager;
$this->moduleHandler = $moduleHandler;
}
/**
* Renders a table of available schemas.
*
* @return array
* The renderable array for the overview table.
*/
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;
}
/**
* Builds a renderable list of operation links for a schema.
*
* @param string $pluginId
* The plugin id.
* @param array $pluginDefinition
* The plugin definition array.
*
* @return array
* A renderable array of operation links.
*/
protected function buildOperations($pluginId, array $pluginDefinition) {
$build = [
'#type' => 'operations',
'#links' => $this
->getOperations($pluginId, $pluginDefinition),
];
return $build;
}
/**
* Provides an array of information to build a list of operation links.
*
* @param $pluginId
* The plugin id.
* @param $pluginDefinition
* The plugin definition array.
*
* @return array
* An associative array of operation link data for this list, keyed by
* operation name, containing the following key-value pairs:
* - title: The localized title of the operation.
* - url: An instance of \Drupal\Core\Url for the operation URL.
* - weight: The weight of this operation.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SchemaOverviewController:: |
protected | property | The module handler service. | |
SchemaOverviewController:: |
protected | property | The schema plugin manager service. | |
SchemaOverviewController:: |
protected | function | Builds a renderable list of operation links for a schema. | |
SchemaOverviewController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
SchemaOverviewController:: |
protected | function | Provides an array of information to build a list of operation links. | |
SchemaOverviewController:: |
public | function | Renders a table of available schemas. | |
SchemaOverviewController:: |
public | function | SchemaOverviewController constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |