FavoriteAnimalTestForm.php

Same filename in other branches
  1. 8.9.x core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
  2. 10 core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
  3. 11.x core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php

Namespace

Drupal\block_test\Form

File

core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php

View source
<?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) {
        $this->messenger()
            ->addStatus($this->t('Your favorite animal is: @favorite_animal', [
            '@favorite_animal' => $form['favorite_animal']['#value'],
        ]));
    }

}

Classes

Title Deprecated Summary
FavoriteAnimalTestForm Form that performs favorite animal test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.