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