summaryrefslogtreecommitdiffstats
path: root/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
blob: 3ad55edff2c1cfe76ac56f44f64907b28d683b5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

namespace Drupal\block_test\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Form that performs favorite animal test.
 *
 * @internal
 */
class FavoriteAnimalTestForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'block_test_form_favorite_animal_test';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['favorite_animal'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Your favorite animal.')
    ];

    $form['submit_animal'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit your chosen animal'),
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    drupal_set_message($this->t('Your favorite animal is: @favorite_animal', ['@favorite_animal' => $form['favorite_animal']['#value']]));
  }

}