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 class {{ class_name }} extends ConfigFormBase {% endblock %}
25 {% block class_construct %}
26 {% if services is not empty %}
28 * Constructs a new {{ class_name }} object.
30 public function __construct(
31 ConfigFactoryInterface $config_factory,
32 {{ servicesAsParameters(services)|join(',\n ') }}
34 parent::__construct($config_factory);
35 {{ serviceClassInitialization(services) }}
41 {% block class_create %}
42 {% if services is not empty %}
43 public static function create(ContainerInterface $container) {
45 $container->get('config.factory'),
46 {{ serviceClassInjection(services) }}
53 {% block class_methods %}
57 protected function getEditableConfigNames() {
59 '{{module_name}}.{{class_name_short}}',
66 public function getFormId() {
73 public function buildForm(array $form, FormStateInterface $form_state) {
74 $config = $this->config('{{module_name}}.{{class_name_short}}');
75 {% for input in inputs %}
76 {% if input.fieldset is defined and input.fieldset is not empty %}
77 $form['{{ input.fieldset }}']['{{ input.name }}'] = [
79 $form['{{ input.name }}'] = [
81 '#type' => '{{ input.type }}',
82 '#title' => $this->t('{{ input.label|e }}'),
83 {% if input.description is defined and input.description|length %}
84 '#description' => $this->t('{{ input.description|e }}'),
86 {% if input.options is defined and input.options is not empty %}
87 '#options' => {{ input.options }},
89 {% if input.maxlength is defined and input.maxlength is not empty %}
90 '#maxlength' => {{ input.maxlength }},
92 {% if input.size is defined and input.size is not empty %}
93 '#size' => {{ input.size }},
95 {% if input.type != 'password_confirm' and input.type != 'fieldset' %}
96 '#default_value' => $config->get('{{ input.name }}'),
100 return parent::buildForm($form, $form_state);
106 public function validateForm(array &$form, FormStateInterface $form_state) {
107 parent::validateForm($form, $form_state);
113 public function submitForm(array &$form, FormStateInterface $form_state) {
114 parent::submitForm($form, $form_state);
116 $this->config('{{module_name}}.{{class_name_short}}')
117 {% for input in inputs %}
118 ->set('{{ input.name }}', $form_state->getValue('{{ input.name }}'))