Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / templates / module / src / Form / form-config.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 Drupal\{{module_name}}\Form\{{ class_name }}.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{module_name}}\Form;
9 {% endblock %}
10
11 {% block use_class %}
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;
17 {% endif %}
18 {% endblock %}
19
20 {% block class_declaration %}
21 /**
22  * Class {{ class_name }}.
23  */
24 class {{ class_name }} extends ConfigFormBase {% endblock %}
25 {% block class_construct %}
26 {% if services is not empty %}
27   /**
28    * Constructs a new {{ class_name }} object.
29    */
30   public function __construct(
31     ConfigFactoryInterface $config_factory,
32       {{ servicesAsParameters(services)|join(',\n    ') }}
33     ) {
34     parent::__construct($config_factory);
35     {{ serviceClassInitialization(services) }}
36   }
37
38 {% endif %}
39 {% endblock %}
40
41 {% block class_create %}
42 {% if services is not empty %}
43   public static function create(ContainerInterface $container) {
44     return new static(
45       $container->get('config.factory'),
46       {{ serviceClassInjection(services) }}
47     );
48   }
49
50 {% endif %}
51 {% endblock %}
52
53 {% block class_methods %}
54   /**
55    * {@inheritdoc}
56    */
57   protected function getEditableConfigNames() {
58     return [
59       '{{module_name}}.{{class_name_short}}',
60     ];
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function getFormId() {
67     return '{{form_id}}';
68   }
69
70   /**
71    * {@inheritdoc}
72    */
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 }}'] = [
78 {% else %}
79     $form['{{ input.name }}'] = [
80 {% endif %}
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 }}'),
85 {% endif %}
86 {% if input.options is defined and input.options is not empty %}
87       '#options' => {{ input.options }},
88 {% endif %}
89 {% if input.maxlength is defined and input.maxlength is not empty %}
90       '#maxlength' => {{ input.maxlength }},
91 {% endif %}
92 {% if input.size is defined and input.size is not empty %}
93       '#size' => {{ input.size }},
94 {% endif %}
95 {% if input.type != 'password_confirm' and input.type != 'fieldset' %}
96       '#default_value' => $config->get('{{ input.name }}'),
97 {% endif %}
98     ];
99 {% endfor %}
100     return parent::buildForm($form, $form_state);
101   }
102
103   /**
104    * {@inheritdoc}
105    */
106   public function validateForm(array &$form, FormStateInterface $form_state) {
107     parent::validateForm($form, $form_state);
108   }
109
110   /**
111    * {@inheritdoc}
112    */
113   public function submitForm(array &$form, FormStateInterface $form_state) {
114     parent::submitForm($form, $form_state);
115
116     $this->config('{{module_name}}.{{class_name_short}}')
117 {% for input in inputs %}
118       ->set('{{ input.name }}', $form_state->getValue('{{ input.name }}'))
119 {% endfor %}
120       ->save();
121   }
122 {% endblock %}