1 {% extends "base/class.php.twig" %}
4 Drupal\{{module_name}}\Form\{{ class_name }}.
7 {% block namespace_class %}
8 namespace Drupal\{{module_name}}\Form;
12 use Drupal\Core\Form\ConfigFormBase;
13 use Drupal\Core\Form\FormStateInterface;
14 {% if services is not empty %}
15 use Drupal\Core\Config\ConfigFactoryInterface;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
20 {% block class_declaration %}
22 * Class {{ class_name }}.
24 * @package Drupal\{{module_name}}\Form
26 class {{ class_name }} extends ConfigFormBase {% endblock %}
27 {% block class_construct %}
28 {% if services is not empty %}
30 * Constructs a new {{ class_name }} object.
32 public function __construct(
33 ConfigFactoryInterface $config_factory,
34 {{ servicesAsParameters(services)|join(',\n ') }}
36 parent::__construct($config_factory);
37 {{ serviceClassInitialization(services) }}
43 {% block class_create %}
44 {% if services is not empty %}
45 public static function create(ContainerInterface $container) {
47 $container->get('config.factory'),
48 {{ serviceClassInjection(services) }}
55 {% block class_methods %}
59 protected function getEditableConfigNames() {
61 '{{module_name}}.{{class_name_short}}',
68 public function getFormId() {
75 public function buildForm(array $form, FormStateInterface $form_state) {
76 $config = $this->config('{{module_name}}.{{class_name_short}}');
77 {% for input in inputs %}
78 {% if input.fieldset is defined and input.fieldset is not empty %}
79 $form['{{ input.fieldset }}']['{{ input.name }}'] = [
81 $form['{{ input.name }}'] = [
83 '#type' => '{{ input.type }}',
84 '#title' => $this->t('{{ input.label|e }}'),
85 {% if input.description is defined and input.description is not empty %}
86 '#description' => $this->t('{{ input.description|e }}'),
88 {% if input.options is defined and input.options is not empty %}
89 '#options' => {{ input.options }},
91 {% if input.maxlength is defined and input.maxlength is not empty %}
92 '#maxlength' => {{ input.maxlength }},
94 {% if input.size is defined and input.size is not empty %}
95 '#size' => {{ input.size }},
97 {% if input.type != 'password_confirm' and input.type != 'fieldset' %}
98 '#default_value' => $config->get('{{ input.name }}'),
102 return parent::buildForm($form, $form_state);
108 public function validateForm(array &$form, FormStateInterface $form_state) {
109 parent::validateForm($form, $form_state);
115 public function submitForm(array &$form, FormStateInterface $form_state) {
116 parent::submitForm($form, $form_state);
118 $this->config('{{module_name}}.{{class_name_short}}')
119 {% for input in inputs %}
120 ->set('{{ input.name }}', $form_state->getValue('{{ input.name }}'))