You are here

public function SearchApiQuery::buildOptionsForm in Search API 8

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

File

src/Plugin/views/query/SearchApiQuery.php, line 378

Class

SearchApiQuery
Defines a Views query class for searching on Search API indexes.

Namespace

Drupal\search_api\Plugin\views\query

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['skip_access'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip item access checks'),
    '#description' => $this
      ->t("By default, an additional access check will be executed for each item returned by the search query. However, since removing results this way will break paging and result counts, it is preferable to configure the view in a way that it will only return accessible results. If you are sure that only accessible results will be returned in the search, or if you want to show results to which the user normally wouldn't have access, you can enable this option to skip those additional access checks. This should be used with care."),
    '#default_value' => $this->options['skip_access'],
    '#weight' => -1,
  ];
  $form['bypass_access'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Bypass access checks'),
    '#description' => $this
      ->t('If the underlying search index has access checks enabled (for example, through the "Content access" processor), this option allows you to disable them for this view. This will never disable any filters placed on this view.'),
    '#default_value' => $this->options['bypass_access'],
  ];
  $form['bypass_access']['#states']['visible'][':input[name="query[options][skip_access]"]']['checked'] = TRUE;
  if ($this
    ->getModuleHandler()
    ->moduleExists('facets')) {
    $form['preserve_facet_query_args'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Preserve facets while using filters'),
      '#description' => $this
        ->t("By default, changing an exposed filter would reset all selected facets. This option allows you to prevent this behavior."),
      '#default_value' => $this->options['preserve_facet_query_args'],
    ];
  }
  else {
    $form['preserve_facet_query_args'] = [
      '#type' => 'value',
      '#value' => FALSE,
    ];
  }
}