Form.html.twig
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @file
* Contains \Drupal\{{ module }}\Form\{{ class }}.
*/
namespace Drupal\{{ module }}\Form;
use Drupal\Core\Form\{% if config %}Config{% endif %}FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
class {{ class }} extends {% if config %}Config{% endif %}FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{ form_id }}';
}
{% if config %}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('{{ module }}.settings');
foreach (Element::children($form) as $variable) {
$config->set($variable, $form_state->getValue($form[$variable]['#parents']));
}
$config->save();
if (method_exists($this, '_submitForm')) {
$this->_submitForm($form, $form_state);
}
parent::submitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['{{ module }}.settings'];
}
{% endif %}
}