You are here

public function SearchBlockForm::buildForm in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/search/src/Form/SearchBlockForm.php \Drupal\search\Form\SearchBlockForm::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/src/Form/SearchBlockForm.php, line 80
Contains \Drupal\search\Form\SearchBlockForm.

Class

SearchBlockForm
Builds the search form for the search block.

Namespace

Drupal\search\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Set up the form to submit using GET to the correct search page.
  $entity_id = $this->searchPageRepository
    ->getDefaultSearchPage();
  if (!$entity_id) {
    $form['message'] = array(
      '#markup' => $this
        ->t('Search is currently disabled'),
    );
    return $form;
  }
  $route = 'search.view_' . $entity_id;
  $form['#action'] = $this
    ->url($route);
  $form['#method'] = 'get';
  $form['keys'] = array(
    '#type' => 'search',
    '#title' => $this
      ->t('Search'),
    '#title_display' => 'invisible',
    '#size' => 15,
    '#default_value' => '',
    '#attributes' => array(
      'title' => $this
        ->t('Enter the terms you wish to search for.'),
    ),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Search'),
    // Prevent op from showing up in the query string.
    '#name' => '',
  );

  // SearchPageRepository::getDefaultSearchPage() depends on search.settings.
  $this->renderer
    ->addCacheableDependency($form, $this->configFactory
    ->get('search.settings'));
  return $form;
}