You are here

public function SearchForm::buildForm in Google Search Appliance 8

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/SearchForm.php, line 27

Class

SearchForm
Provides the search form.

Namespace

Drupal\google_appliance\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $query = '') {
  $prompt = $this
    ->t('Enter the terms you wish to search for.');

  // Basic search.
  $form['basic'] = [
    '#type' => 'container',
  ];
  $form['basic']['search_keys'] = [
    '#type' => 'textfield',
    '#default_value' => $query,
    '#attributes' => [
      'title' => $prompt,
      'placeholder' => $prompt,
    ],
    '#title' => $prompt,
    '#title_display' => 'invisible',
  ];

  // @todo: sort.
  $form['basic']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Search'),
  ];

  // Use core search CSS in addition to this module's css
  // (keep it general in case core search is enabled).
  $form['#attributes']['class'][] = 'search-form';
  $form['#attributes']['class'][] = 'search-google-appliance-search-form';
  return $form;
}