You are here

public function SearchApiDisplay::getFields in Facets 8

Returns an array of fields that are defined on the facet source.

This returns an array of fields that are defined on the source. This array is keyed by the field's machine name and has values of the field's label.

Return value

array An array of available fields.

Overrides FacetSourcePluginBase::getFields

1 call to SearchApiDisplay::getFields()
SearchApiDisplay::buildConfigurationForm in src/Plugin/facets/facet_source/SearchApiDisplay.php
Form constructor.

File

src/Plugin/facets/facet_source/SearchApiDisplay.php, line 226

Class

SearchApiDisplay
Provides a facet source based on a Search API display.

Namespace

Drupal\facets\Plugin\facets\facet_source

Code

public function getFields() {
  $indexed_fields = [];
  $index = $this
    ->getIndex();
  $fields = $index
    ->getFields();
  $server = $index
    ->getServerInstance();
  $backend = $server
    ->getBackend();
  foreach ($fields as $field) {
    $data_type_plugin_id = $field
      ->getDataTypePlugin()
      ->getPluginId();
    $query_types = $this
      ->getQueryTypesForDataType($backend, $data_type_plugin_id);
    if (!empty($query_types)) {
      $indexed_fields[$field
        ->getFieldIdentifier()] = $field
        ->getLabel() . ' (' . $field
        ->getPropertyPath() . ')';
    }
  }
  return $indexed_fields;
}