You are here

protected function ViewsAutocompleteFiltersTrait::getFieldOptions in Views Autocomplete Filters 8

Fetches the autocomplete field options.

Return value

array The list of options.

1 call to ViewsAutocompleteFiltersTrait::getFieldOptions()
ViewsAutocompleteFiltersTrait::buildOptionsForm in src/Plugin/views/filter/ViewsAutocompleteFiltersTrait.php
Build the options form.

File

src/Plugin/views/filter/ViewsAutocompleteFiltersTrait.php, line 117

Class

ViewsAutocompleteFiltersTrait
Provides common methods for all Views Autocomplete Filters.

Namespace

Drupal\views_autocomplete_filters\Plugin\views\filter

Code

protected function getFieldOptions() {
  $field_options = [];

  // Limit options to fields with the same name.

  /** @var \Drupal\views\Plugin\views\field\FieldHandlerInterface $handler */
  foreach ($this->view->display_handler
    ->getHandlers('field') as $id => $handler) {
    if (in_array($this->realField, [
      $handler->field,
      $handler->field . '_value',
      $handler->realField . '_value',
    ])) {
      $field_options_all = $this->view->display_handler
        ->getFieldLabels();
      $field_options[$id] = $field_options_all[$id];
    }
  }
  if (empty($field_options)) {
    $field_options[''] = $this
      ->t('Add some fields to view');
  }
  return $field_options;
}