You are here

public function SearchApiFulltext::buildExposedForm in Search API 8

Render our chunk of the exposed filter form when selecting

You can override this if it doesn't do what you expect.

Overrides FilterPluginBase::buildExposedForm

File

src/Plugin/views/filter/SearchApiFulltext.php, line 248

Class

SearchApiFulltext
Defines a filter for adding a fulltext search to the view.

Namespace

Drupal\search_api\Plugin\views\filter

Code

public function buildExposedForm(&$form, FormStateInterface $form_state) {
  parent::buildExposedForm($form, $form_state);
  if (empty($this->options['exposed'])) {
    return;
  }
  if ($this->options['expose']['expose_fields']) {
    $fields = $this
      ->getFulltextFields();
    $configured_fields = $this->options['fields'];

    // Only keep the configured fields.
    if (!empty($configured_fields)) {
      $configured_fields = array_flip($configured_fields);
      $fields = array_intersect_key($fields, $configured_fields);
    }
    $searched_fields_identifier = $this->options['id'] . '_searched_fields';
    if (!empty($this->options['expose']['searched_fields_id'])) {
      $searched_fields_identifier = $this->options['expose']['searched_fields_id'];
    }
    $form[$searched_fields_identifier] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Search fields'),
      '#options' => $fields,
      '#multiple' => TRUE,
      '#size' => min(count($fields), 5),
    ];
  }
}