You are here

public function SearchApiBaseFacetSource::getQueryTypesForFacet in Facets 8

Returns the allowed query types for a given facet for the facet source.

Parameters

\Drupal\facets\FacetInterface $facet: The facet we should get query types for.

Return value

string[] array of allowed query types

Throws

\Drupal\facets\Exception\Exception An error when no query types are found.

Overrides FacetSourcePluginBase::getQueryTypesForFacet

File

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

Class

SearchApiBaseFacetSource
A base class for Search API facet sources.

Namespace

Drupal\facets\Plugin\facets\facet_source

Code

public function getQueryTypesForFacet(FacetInterface $facet) {

  // Get our Facets Field Identifier, which is equal to the Search API Field
  // identifier.
  $field_id = $facet
    ->getFieldIdentifier();

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

  // Get the Search API Backend.
  $backend = $server
    ->getBackend();
  $fields = $this
    ->getIndex()
    ->getFields();
  if (isset($fields[$field_id])) {
    return $this
      ->getQueryTypesForDataType($backend, $fields[$field_id]
      ->getType());
  }
  throw new InvalidQueryTypeException("No available query types were found for facet {$facet->getName()}");
}