ComposableSchema.php in GraphQL 8.4
File
src/Plugin/GraphQL/Schema/ComposableSchema.php
View source
<?php
namespace Drupal\graphql\Plugin\GraphQL\Schema;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\graphql\GraphQL\ResolverRegistry;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class ComposableSchema extends SdlSchemaPluginBase implements ConfigurableInterface, PluginFormInterface {
use StringTranslationTrait;
public function getResolverRegistry() {
return new ResolverRegistry();
}
protected function getExtensions() {
return array_map(function ($id) {
return $this->extensionManager
->createInstance($id);
}, array_filter($this
->getConfiguration()['extensions']));
}
protected function getSchemaDefinition() {
return <<<GQL
type Schema {
query: Query
}
type Query
GQL;
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) : void {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
public function defaultConfiguration() {
return [];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$extensions = $this->extensionManager
->getDefinitions();
$form['extensions'] = [
'#type' => 'checkboxes',
'#required' => FALSE,
'#title' => $this
->t('Enabled extensions'),
'#options' => [],
'#default_value' => $this->configuration['extensions'] ?? [],
];
foreach ($extensions as $key => $extension) {
$form['extensions']['#options'][$key] = $extension['name'] ?? $extension['id'];
if (!empty($extension['description'])) {
$form['extensions'][$key]['#description'] = $extension['description'];
}
}
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $formState) : void {
}
public function submitConfigurationForm(array &$form, FormStateInterface $formState) : void {
}
}
Classes
Name |
Description |
ComposableSchema |
Plugin annotation
@Schema(
id = "composable",
name = "Composable schema"
) |