You are here

public function SearchApiBaseFacetSource::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 SearchApiBaseFacetSource::getFields()
SearchApiBaseFacetSource::buildConfigurationForm in src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php
Form constructor.

File

src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php, line 118

Class

SearchApiBaseFacetSource
A base class for Search API facet sources.

Namespace

Drupal\facets\Plugin\facets\facet_source

Code

public function getFields() {
  $indexed_fields = [];
  $fields = $this
    ->getIndex()
    ->getFields();

  // Get the Search API Server.
  $server = $this
    ->getIndex()
    ->getServerInstance();

  // Get the Search API Backend.
  $backend = $server
    ->getBackend();
  foreach ($fields as $field) {
    $query_types = $this
      ->getQueryTypesForDataType($backend, $field
      ->getDataTypePlugin()
      ->getPluginId());
    if (!empty($query_types)) {
      $indexed_fields[$field
        ->getFieldIdentifier()] = $field
        ->getLabel() . ' (' . $field
        ->getPropertyPath() . ')';
    }
  }
  return $indexed_fields;
}