You are here

public function SearchEmbeddedForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/search/tests/modules/search_embedded_form/src/Form/SearchEmbeddedForm.php \Drupal\search_embedded_form\Form\SearchEmbeddedForm::buildForm()
  2. 10 core/modules/search/tests/modules/search_embedded_form/src/Form/SearchEmbeddedForm.php \Drupal\search_embedded_form\Form\SearchEmbeddedForm::buildForm()

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

core/modules/search/tests/modules/search_embedded_form/src/Form/SearchEmbeddedForm.php, line 25

Class

SearchEmbeddedForm
Form controller for search_embedded_form form.

Namespace

Drupal\search_embedded_form\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $count = \Drupal::state()
    ->get('search_embedded_form.submit_count');
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Your name'),
    '#maxlength' => 255,
    '#default_value' => '',
    '#required' => TRUE,
    '#description' => $this
      ->t('Times form has been submitted: %count', [
      '%count' => $count,
    ]),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Send away'),
  ];
  return $form;
}