3 use Drupal\Core\Form\FormStateInterface;
6 {% block file_methods %}
7 {% if form_id is not empty %}
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 }}
14 function {{ module }}_form_{{ form_id }}_alter(&$form, FormStateInterface $form_state) {
15 drupal_set_message('{{ module }}_form_{{ form_id }}_alter() executed.');
18 * Implements hook_form_alter() on behalf of {{ module }}.module.
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.');
26 {%- if metadata.unset -%}
27 {% for field in metadata.unset %}
28 $form['{{ field }}']['#access'] = FALSE;
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 }}'),
40 {%- if input.options is defined and input.options|length -%}
41 '#options' => {{ input.options }},
43 {%- if input.maxlength is defined and input.maxlength|length -%}
44 '#maxlength' => {{ input.maxlength }},
46 {%- if input.size is defined and input.size|length -%}
47 '#size' => {{ input.size }},
49 {%- if input.default_value is defined and input.default_value|length -%}
50 '#default_value' => '{{ input.default_value }}',
52 {%- if input.weight is defined and input.weight|length -%}
53 '#weight' => '{{ input.weight }}',
59 {% if form_id is empty %}