Yaffs site version 1.1
[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  * @package Drupal\{{module_name}}\Form
24  */
25 class {{ class_name }} extends FormBase {% endblock %}
26 {% block class_construct %}
27 {% if services is not empty %}
28   /**
29    * Constructs a new {{ class_name }} object.
30    */
31   public function __construct(
32     {{ servicesAsParameters(services)|join(',\n    ') }}
33   ) {
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 {{ serviceClassInjection(services) }}
45     );
46   }
47
48 {% endif %}
49 {% endblock %}
50
51 {% block class_methods %}
52
53   /**
54    * {@inheritdoc}
55    */
56   public function getFormId() {
57     return '{{form_id}}';
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function buildForm(array $form, FormStateInterface $form_state) {
64 {% for input in inputs %}
65 {% if input.fieldset|length %}
66     $form['{{ input.fieldset }}']['{{ input.name }}'] = [
67 {% else %}
68     $form['{{ input.name }}'] = [
69 {% endif %}
70       '#type' => '{{ input.type }}',
71       '#title' => $this->t('{{ input.label|e }}'),
72 {% if input.description|length %}
73       '#description' => $this->t('{{ input.description|e }}'),
74 {% endif %}
75 {% if input.options|length %}
76       '#options' => {{ input.options }},
77 {% endif %}
78 {% if input.maxlength|length %}
79       '#maxlength' => {{ input.maxlength }},
80 {% endif %}
81 {% if input.size|length %}
82       '#size' => {{ input.size }},
83 {% endif %}
84     ];
85 {% endfor %}
86     $form['submit'] = [
87       '#type' => 'submit',
88       '#value' => $this->t('Submit'),
89     ];
90
91     return $form;
92   }
93
94   /**
95    * {@inheritdoc}
96    */
97   public function validateForm(array &$form, FormStateInterface $form_state) {
98     parent::validateForm($form, $form_state);
99   }
100
101   /**
102    * {@inheritdoc}
103    */
104   public function submitForm(array &$form, FormStateInterface $form_state) {
105     // Display result.
106     foreach ($form_state->getValues() as $key => $value) {
107       drupal_set_message($key . ': ' . $value);
108     }
109
110   }
111 {% endblock %}