You are here

public function TextForm::buildForm in Examples for Developers 3.x

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

modules/theming_example/src/Form/TextForm.php, line 28

Class

TextForm
A simple form that displays a textfield and submit button.

Namespace

Drupal\theming_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Please input something!'),
    '#required' => TRUE,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Go'),
  ];
  return $form;
}