You are here

public function SearchApiMoreLikeThis::buildOptionsForm in Search API 8

Provide a form to edit options for this plugin.

Overrides SearchApiStandard::buildOptionsForm

File

src/Plugin/views/argument/SearchApiMoreLikeThis.php, line 35

Class

SearchApiMoreLikeThis
Defines a contextual filter for displaying a "More Like This" list.

Namespace

Drupal\search_api\Plugin\views\argument

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  unset($form['break_phrase']);
  unset($form['not']);
  $index = Index::load(substr($this->table, 17));
  $fields = [];
  foreach ($index
    ->getFields() as $key => $field) {
    $fields[$key] = $field
      ->getLabel();
  }
  if ($fields) {
    $form['fields'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Fields for similarity'),
      '#description' => $this
        ->t('Select the fields that will be used for finding similar content. If no fields are selected, all available fields will be used.'),
      '#options' => $fields,
      '#size' => min(8, count($fields)),
      '#multiple' => TRUE,
      '#default_value' => $this->options['fields'],
    ];
  }
  else {
    $form['fields'] = [
      '#type' => 'value',
      '#value' => [],
    ];
  }
}