f4bf25b18c49b3acc313ca451acfe406bf748263
[yaffs-website] / vendor / drupal / console / templates / module / src / Form / form-alter.php.twig
1
2 {% block use_class %}
3 use Drupal\Core\Form\FormStateInterface;
4 {% endblock %}
5
6 {% block file_methods %}
7 {% if form_id is not empty %}
8 /**
9  * Implements hook_form_FORM_ID_alter() on behalf of {{ module }}.module.
10 {% if metadata.class is defined %}
11  * @see \{{ metadata.class }} method {{ metadata.method }} at {{ metadata.file }}
12 {% endif %}
13  */
14 function {{ module }}_form_{{ form_id }}_alter(&$form, FormStateInterface $form_state) {
15     drupal_set_message('{{ module }}_form_{{ form_id }}_alter() executed.');
16 {% else %}
17 /**
18  * Implements hook_form_alter() on behalf of {{ module }}.module.
19  */
20 function {{ module }}_form_alter(&$form, FormStateInterface $form_state, $form_id) {
21     // Change form id here
22     if ($form_id == 'form_test_alter_form') {
23         drupal_set_message('form_test_form_alter() executed.');
24 {% endif %}
25
26 {%- if metadata.unset -%}
27 {% for field in metadata.unset %}
28         $form['{{ field }}']['#access'] = FALSE;
29 {% endfor %}
30 {% endif %}
31
32 {% if inputs %}
33 {% for input in inputs %}
34         $form['{{ input.name }}'] = [
35             '#type' => '{{ input.type }}',
36             '#title' => t('{{ input.label|e }}'),
37     {%- if input.description is defined and input.description is defined -%}
38             '#description' => t('{{ input.description|e }}'),
39     {% endif %}
40     {%- if input.options is defined and input.options|length -%}
41             '#options' => {{ input.options }},
42     {% endif %}
43     {%- if input.maxlength is defined and input.maxlength|length -%}
44             '#maxlength' => {{ input.maxlength }},
45     {% endif %}
46     {%- if input.size is defined and input.size|length -%}
47             '#size' => {{ input.size }},
48     {% endif %}
49     {%- if input.default_value is defined and input.default_value|length -%}
50             '#default_value' => '{{ input.default_value }}',
51     {% endif %}
52     {%- if input.weight is defined and input.weight|length -%}
53             '#weight' => '{{ input.weight }}',
54     {% endif %}
55         ];
56
57 {% endfor %}
58 {% endif %}
59 {% if form_id is empty %}
60     }
61 {% endif %}
62 }
63 {% endblock %}