JsonQueryMapConfigForm.php in GraphQL 8.3
File
src/Form/JsonQueryMapConfigForm.php
View source
<?php
namespace Drupal\graphql\Form;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class JsonQueryMapConfigForm extends ConfigFormBase {
protected $cacheBackend;
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('cache.default'));
}
public function __construct(ConfigFactoryInterface $configFactory, CacheBackendInterface $cacheBackend) {
parent::__construct($configFactory);
$this->cacheBackend = $cacheBackend;
}
public function getFormId() {
return 'graphql_query_map_json_config';
}
protected function getEditableConfigNames() {
return [
'graphql.query_map_json.config',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('graphql.query_map_json.config');
$form['lookup_paths'] = [
'#type' => 'textarea',
'#title' => $this
->t('Lookup paths'),
'#default_value' => implode("\n", $config
->get('lookup_paths') ?: []),
'#description' => $this
->t('The path patterns to use for the query map lookup.'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->cacheBackend
->delete('graphql_query_map_json_versions');
$paths = array_map('trim', explode("\n", $form_state
->getValue('lookup_paths', '')));
$this
->config('graphql.query_map_json.config')
->set('lookup_paths', $paths)
->save();
parent::submitForm($form, $form_state);
}
}