You are here

public function SearchBoxForm::buildForm in Panopoly Search 8.2

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

src/Form/SearchBoxForm.php, line 52

Class

SearchBoxForm
Search box form.

Namespace

Drupal\panopoly_search\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $search_page_route = panopoly_search_page_route();
  if (empty($search_page_route)) {
    $form['message'] = [
      '#markup' => $this
        ->t('Search is currently disabled'),
    ];
    return $form;
  }
  $form['#action'] = Url::fromRoute($search_page_route)
    ->toString();
  $form['#method'] = 'get';
  $form['keys'] = [
    '#type' => 'search',
    '#title' => $this
      ->t('Enter your keywords'),
    '#size' => 15,
    '#default_value' => '',
    '#attributes' => [
      'title' => $this
        ->t('Enter the terms you wish to search for.'),
    ],
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Search'),
    // Prevent op from showing up in the query string.
    '#name' => '',
    // Get the default style from Bartik.
    '#attributes' => [
      'class' => [
        'search-form__submit',
      ],
    ],
  ];
  return $form;
}