You are here

public function SearchApiDisplay::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/SearchApiDisplay.php, line 248

Class

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

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();

  /** @var \Drupal\search_api\IndexInterface $index */
  $index = $this
    ->getIndex();

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

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