1 {% extends "base/class.php.twig" %}
4 \Drupal\{{module_name}}\Form\{{ class_name }}.
7 {% block namespace_class %}
8 namespace Drupal\{{module_name}}\Form;
12 use Drupal\Core\Form\FormBase;
13 use Drupal\Core\Form\FormStateInterface;
14 {% if services is not empty %}
15 use Symfony\Component\DependencyInjection\ContainerInterface;
19 {% block class_declaration %}
21 * Class {{ class_name }}.
23 class {{ class_name }} extends FormBase {% endblock %}
24 {% block class_construct %}
25 {% if services is not empty %}
27 * Constructs a new {{ class_name }} object.
29 public function __construct(
30 {{ servicesAsParameters(services)|join(',\n ') }}
32 {{ serviceClassInitialization(services) }}
38 {% block class_create %}
39 {% if services is not empty %}
40 public static function create(ContainerInterface $container) {
42 {{ serviceClassInjection(services) }}
49 {% block class_methods %}
54 public function getFormId() {
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 }}'] = [
66 $form['{{ input.name }}'] = [
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 }}'),
73 {% if input.options is defined and input.options|length %}
74 '#options' => {{ input.options }},
76 {% if input.maxlength is defined and input.maxlength|length %}
77 '#maxlength' => {{ input.maxlength }},
79 {% if input.size is defined and input.size|length %}
80 '#size' => {{ input.size }},
82 {% if input.default_value is defined and input.default_value|length %}
83 '#default_value' => {{ input.default_value }},
85 {% if input.weight is defined and input.weight|length %}
86 '#weight' => '{{ input.weight }}',
92 '#value' => $this->t('Submit'),
101 public function validateForm(array &$form, FormStateInterface $form_state) {
102 parent::validateForm($form, $form_state);
108 public function submitForm(array &$form, FormStateInterface $form_state) {
110 foreach ($form_state->getValues() as $key => $value) {
111 drupal_set_message($key . ': ' . $value);