You are here

public function SuggestionBlockForm::buildForm in Autocomplete Search Suggestions 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/SuggestionBlockForm.php \Drupal\suggestion\Form\SuggestionBlockForm::buildForm()
  2. 8 src/Form/SuggestionBlockForm.php \Drupal\suggestion\Form\SuggestionBlockForm::buildForm()

A search block form.

Parameters

array $form: A drupal form array.

Drupal\Core\Form\FormStateInterface $form_state: A Drupal form state object.

Return value

array A Drupal form array.

Overrides FormInterface::buildForm

File

src/Form/SuggestionBlockForm.php, line 25

Class

SuggestionBlockForm
Builds the search form for the search block.

Namespace

Drupal\suggestion\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cfg = SuggestionHelper::getConfig();
  $form['#action'] = $cfg->action;
  $form['#form_id'] = 'suggestion_block_form';
  $form['#method'] = 'get';
  $form['keys'] = [
    '#type' => 'search',
    '#title' => $this
      ->t('Search'),
    '#title_display' => 'invisible',
    '#size' => $cfg->max,
    '#default_value' => '',
    '#attributes' => [
      'title' => $this
        ->t('Enter the terms you wish to search for.'),
    ],
    '#autocomplete_route_name' => 'suggestion.autocomplete',
  ];
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#name' => '',
      '#attributes' => [
        'class' => [
          'search-form__submit',
        ],
      ],
      '#value' => $this
        ->t('Search'),
    ],
  ];
  return $form;
}