You are here

public function SearchApiFulltext::buildOptionsForm in Search API 8

Same name in this branch
  1. 8 src/Plugin/views/filter/SearchApiFulltext.php \Drupal\search_api\Plugin\views\filter\SearchApiFulltext::buildOptionsForm()
  2. 8 src/Plugin/views/argument/SearchApiFulltext.php \Drupal\search_api\Plugin\views\argument\SearchApiFulltext::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides SearchApiStandard::buildOptionsForm

File

src/Plugin/views/argument/SearchApiFulltext.php, line 77

Class

SearchApiFulltext
Defines a contextual filter for doing fulltext searches.

Namespace

Drupal\search_api\Plugin\views\argument

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['parse_mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Parse mode'),
    '#description' => $this
      ->t('Choose how the search keys will be parsed.'),
    '#options' => [],
    '#default_value' => $this->options['parse_mode'],
  ];
  foreach ($this
    ->getParseModeManager()
    ->getInstances() as $key => $mode) {
    if ($mode
      ->isHidden()) {
      continue;
    }
    $form['parse_mode']['#options'][$key] = $mode
      ->label();
    if ($mode
      ->getDescription()) {
      $states['visible'][':input[name="options[parse_mode]"]']['value'] = $key;
      $form["parse_mode_{$key}_description"] = [
        '#type' => 'item',
        '#title' => $mode
          ->label(),
        '#description' => $mode
          ->getDescription(),
        '#states' => $states,
      ];
    }
  }
  $fields = $this
    ->getFulltextFields();
  if (!empty($fields)) {
    $form['fields'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Searched fields'),
      '#description' => $this
        ->t('Select the fields that will be searched. If no fields are selected, all available fulltext fields will be searched.'),
      '#options' => $fields,
      '#size' => min(4, count($fields)),
      '#multiple' => TRUE,
      '#default_value' => $this->options['fields'],
    ];
    $form['conjunction'] = [
      '#title' => $this
        ->t('Operator'),
      '#description' => $this
        ->t('Determines how multiple keywords entered for the search will be combined.'),
      '#type' => 'radios',
      '#options' => [
        'AND' => $this
          ->t('Contains all of these words'),
        'OR' => $this
          ->t('Contains any of these words'),
      ],
      '#default_value' => $this->options['conjunction'],
    ];
  }
  else {
    $form['fields'] = [
      '#type' => 'value',
      '#value' => [],
    ];
  }
}