{% block use_class %} use Drupal\Core\Form\FormStateInterface; {% endblock %} {% block file_methods %} {% if form_id is not empty %} /** * Implements hook_form_FORM_ID_alter() on behalf of {{ module }}.module. {% if metadata.class is defined %} * @see \{{ metadata.class }} method {{ metadata.method }} at {{ metadata.file }} {% endif %} */ function {{ module }}_form_{{ form_id }}_alter(&$form, FormStateInterface $form_state) { drupal_set_message('{{ module }}_form_{{ form_id }}_alter() executed.'); {% else %} /** * Implements hook_form_alter() on behalf of {{ module }}.module. */ function {{ module }}_form_alter(&$form, FormStateInterface $form_state, $form_id) { // Change form id here if ($form_id == 'form_test_alter_form') { drupal_set_message('form_test_form_alter() executed.'); {% endif %} {%- if metadata.unset -%} {% for field in metadata.unset %} $form['{{ field }}']['#access'] = FALSE; {% endfor %} {% endif %} {% if inputs %} {% for input in inputs %} $form['{{ input.name }}'] = [ '#type' => '{{ input.type }}', '#title' => t('{{ input.label|e }}'), {%- if input.description is defined -%} '#description' => t('{{ input.description|e }}'), {% endif %} {%- if input.options is defined and input.options|length -%} '#options' => {{ input.options }}, {% endif %} {%- if input.maxlength|length -%} '#maxlength' => {{ input.maxlength }}, {% endif %} {%- if input.size|length -%} '#size' => {{ input.size }}, {% endif %} {%- if input.default_value is defined and input.default_value|length -%} '#default_value' => '{{ input.default_value }}', {% endif %} {%- if input.weight is defined and input.weight|length -%} '#weight' => '{{ input.weight }}', {% endif %} ]; {% endfor %} {% endif %} {% if form_id is empty %} } {% endif %} } {% endblock %}