Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / templates / module / src / Form / form.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\FormBase;
13 use Drupal\Core\Form\FormStateInterface;
14 {% if services is not empty %}
15 use Symfony\Component\DependencyInjection\ContainerInterface;
16 {% endif %}
17 {% endblock %}
18
19 {% block class_declaration %}
20 /**
21  * Class {{ class_name }}.
22  */
23 class {{ class_name }} extends FormBase {% endblock %}
24 {% block class_construct %}
25 {% if services is not empty %}
26   /**
27    * Constructs a new {{ class_name }} object.
28    */
29   public function __construct(
30     {{ servicesAsParameters(services)|join(',\n    ') }}
31   ) {
32 {{ serviceClassInitialization(services) }}
33   }
34
35 {% endif %}
36 {% endblock %}
37
38 {% block class_create %}
39 {% if services is not empty %}
40   public static function create(ContainerInterface $container) {
41     return new static(
42 {{ serviceClassInjection(services) }}
43     );
44   }
45
46 {% endif %}
47 {% endblock %}
48
49 {% block class_methods %}
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getFormId() {
55     return '{{form_id}}';
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function buildForm(array $form, FormStateInterface $form_state) {
62 {% for input in inputs %}
63 {% if input.fieldset is defined and input.fieldset|length %}
64     $form['{{ input.fieldset }}']['{{ input.name }}'] = [
65 {% else %}
66     $form['{{ input.name }}'] = [
67 {% endif %}
68       '#type' => '{{ input.type }}',
69       '#title' => $this->t('{{ input.label|e }}'),
70 {% if input.description is defined and input.description|length %}
71       '#description' => $this->t('{{ input.description|e }}'),
72 {% endif %}
73 {% if input.options is defined and input.options|length %}
74       '#options' => {{ input.options }},
75 {% endif %}
76 {% if input.maxlength is defined and input.maxlength|length %}
77       '#maxlength' => {{ input.maxlength }},
78 {% endif %}
79 {% if input.size is defined and input.size|length %}
80       '#size' => {{ input.size }},
81 {% endif %}
82 {% if input.default_value is defined and input.default_value|length %}
83       '#default_value' => {{ input.default_value }},
84 {% endif %}
85 {% if input.weight is defined and input.weight|length %}
86       '#weight' => '{{ input.weight }}',
87 {% endif %}
88     ];
89 {% endfor %}
90     $form['submit'] = [
91       '#type' => 'submit',
92       '#value' => $this->t('Submit'),
93     ];
94
95     return $form;
96   }
97
98   /**
99    * {@inheritdoc}
100    */
101   public function validateForm(array &$form, FormStateInterface $form_state) {
102     parent::validateForm($form, $form_state);
103   }
104
105   /**
106    * {@inheritdoc}
107    */
108   public function submitForm(array &$form, FormStateInterface $form_state) {
109     // Display result.
110     foreach ($form_state->getValues() as $key => $value) {
111       drupal_set_message($key . ': ' . $value);
112     }
113
114   }
115 {% endblock %}