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 * @package Drupal\{{module_name}}\Form
25 class {{ class_name }} extends FormBase {% endblock %}
26 {% block class_construct %}
27 {% if services is not empty %}
29 * Constructs a new {{ class_name }} object.
31 public function __construct(
32 {{ servicesAsParameters(services)|join(',\n ') }}
34 {{ serviceClassInitialization(services) }}
40 {% block class_create %}
41 {% if services is not empty %}
42 public static function create(ContainerInterface $container) {
44 {{ serviceClassInjection(services) }}
51 {% block class_methods %}
56 public function getFormId() {
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 }}'] = [
68 $form['{{ input.name }}'] = [
70 '#type' => '{{ input.type }}',
71 '#title' => $this->t('{{ input.label|e }}'),
72 {% if input.description|length %}
73 '#description' => $this->t('{{ input.description|e }}'),
75 {% if input.options|length %}
76 '#options' => {{ input.options }},
78 {% if input.maxlength|length %}
79 '#maxlength' => {{ input.maxlength }},
81 {% if input.size|length %}
82 '#size' => {{ input.size }},
88 '#value' => $this->t('Submit'),
97 public function validateForm(array &$form, FormStateInterface $form_state) {
98 parent::validateForm($form, $form_state);
104 public function submitForm(array &$form, FormStateInterface $form_state) {
106 foreach ($form_state->getValues() as $key => $value) {
107 drupal_set_message($key . ': ' . $value);