You are here

public function FederatedSearchPageBlockForm::buildForm in Search API Federated Solr 8.3

Same name and namespace in other branches
  1. 8 src/Form/FederatedSearchPageBlockForm.php \Drupal\search_api_federated_solr\Form\FederatedSearchPageBlockForm::buildForm()
  2. 8.2 src/Form/FederatedSearchPageBlockForm.php \Drupal\search_api_federated_solr\Form\FederatedSearchPageBlockForm::buildForm()
  3. 4.x src/Form/FederatedSearchPageBlockForm.php \Drupal\search_api_federated_solr\Form\FederatedSearchPageBlockForm::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

src/Form/FederatedSearchPageBlockForm.php, line 31
Contains \Drupal\search_api_solr_federated\Form\FederatedSearchPageBlockForm.

Class

FederatedSearchPageBlockForm
Class FederatedSearchPageForm.

Namespace

Drupal\search_api_federated_solr\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $renderer = \Drupal::service('renderer');
  $app_config = \Drupal::config('search_api_federated_solr.search_app.settings');
  $form['#theme'] = 'search_api_federated_solr_block_form';
  $form['search'] = [
    '#type' => 'search',
    '#name' => 'search',
    '#title' => $this
      ->t('Search'),
    '#title_display' => 'invisible',
    '#size' => 15,
    '#default_value' => '',
    '#attributes' => [
      'title' => $this
        ->t('Enter the terms you wish to search for.'),
      'placeholder' => 'Search',
      'autocomplete' => "off",
    ],
    '#provider' => 'search_api_federated_solr',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Search'),
    '#name' => '',
    '#provider' => 'search_api_federated_solr',
  ];

  // Send site name as qs param if app is configured to load w/default site.
  if ($app_config
    ->get('facet.site_name.set_default')) {
    $site_name = Helpers::getSiteName();
    if ($site_name) {
      $form['sm_site_name'] = [
        '#type' => 'hidden',
        '#name' => 'sm_site_name',
        '#default_value' => $site_name,
      ];
    }
  }
  $form['#action'] = \Drupal::urlGenerator()
    ->generateFromRoute('search_api_federated_solr.search');
  $form['#method'] = 'get';

  // Ensure that this form's render cache is invalidated when search app
  // config is updated.
  $renderer
    ->addCacheableDependency($form, $app_config);
  return $form;
}