function SearchEmbeddedForm::buildForm

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. 8.9.x core/modules/search/tests/modules/search_embedded_form/src/Form/SearchEmbeddedForm.php \Drupal\search_embedded_form\Form\SearchEmbeddedForm::buildForm()
  3. 10 core/modules/search/tests/modules/search_embedded_form/src/Form/SearchEmbeddedForm.php \Drupal\search_embedded_form\Form\SearchEmbeddedForm::buildForm()

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', 0);
    $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;
}

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