52ca88bfa2364a662ad3d72d506becf6b1e1cc42
[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  * @package Drupal\{{module_name}}\Form
25  */
26 class {{ class_name }} extends ConfigFormBase {% endblock %}
27 {% block class_construct %}
28 {% if services is not empty %}
29   public function __construct(
30     ConfigFactoryInterface $config_factory,
31       {{ servicesAsParameters(services)|join(',\n    ') }}
32     ) {
33     parent::__construct($config_factory);
34     {{ serviceClassInitialization(services) }}
35   }
36
37 {% endif %}
38 {% endblock %}
39
40 {% block class_create %}
41 {% if services is not empty %}
42   public static function create(ContainerInterface $container) {
43     return new static(
44       $container->get('config.factory'),
45       {{ serviceClassInjection(services) }}
46     );
47   }
48
49 {% endif %}
50 {% endblock %}
51
52 {% block class_methods %}
53   /**
54    * {@inheritdoc}
55    */
56   protected function getEditableConfigNames() {
57     return [
58       '{{module_name}}.{{class_name_short}}',
59     ];
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function getFormId() {
66     return '{{form_id}}';
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function buildForm(array $form, FormStateInterface $form_state) {
73     $config = $this->config('{{module_name}}.{{class_name_short}}');
74 {% for input in inputs %}
75 {% if input.fieldset is defined and input.fieldset is not empty %}
76     $form['{{ input.fieldset }}']['{{ input.name }}'] = [
77 {% else %}
78     $form['{{ input.name }}'] = [
79 {% endif %}
80       '#type' => '{{ input.type }}',
81       '#title' => $this->t('{{ input.label|e }}'),
82 {% if input.description is defined and input.description is not empty %}
83       '#description' => $this->t('{{ input.description|e }}'),
84 {% endif %}
85 {% if input.options is defined and input.options is not empty %}
86       '#options' => {{ input.options }},
87 {% endif %}
88 {% if input.maxlength is defined and input.maxlength is not empty %}
89       '#maxlength' => {{ input.maxlength }},
90 {% endif %}
91 {% if input.size is defined and input.size is not empty %}
92       '#size' => {{ input.size }},
93 {% endif %}
94 {% if input.type != 'password_confirm' and input.type != 'fieldset' %}
95       '#default_value' => $config->get('{{ input.name }}'),
96 {% endif %}
97     ];
98 {% endfor %}
99     return parent::buildForm($form, $form_state);
100   }
101
102   /**
103    * {@inheritdoc}
104    */
105   public function validateForm(array &$form, FormStateInterface $form_state) {
106     parent::validateForm($form, $form_state);
107   }
108
109   /**
110    * {@inheritdoc}
111    */
112   public function submitForm(array &$form, FormStateInterface $form_state) {
113     parent::submitForm($form, $form_state);
114
115     $this->config('{{module_name}}.{{class_name_short}}')
116 {% for input in inputs %}
117       ->set('{{ input.name }}', $form_state->getValue('{{ input.name }}'))
118 {% endfor %}
119       ->save();
120   }
121 {% endblock %}