You are here

protected function SearchApiQueryPreExecute::removeAliasConditions in JSON:API Search API 8

Removes alias conditions from the query.

The index resource adds all filter conditions to the Search API query, which includes the facet URL alias. Remove them to prevent errors for non-existant fields.

Parameters

\Drupal\search_api\Query\ConditionGroupInterface $condition_group: The condition group.

array $aliases: The facet aliases.

1 call to SearchApiQueryPreExecute::removeAliasConditions()
SearchApiQueryPreExecute::includeFacetsInQuery in modules/jsonapi_search_api_facets/src/EventSubscriber/SearchApiQueryPreExecute.php
Alter the Search API query to include Facets if enabled.

File

modules/jsonapi_search_api_facets/src/EventSubscriber/SearchApiQueryPreExecute.php, line 93

Class

SearchApiQueryPreExecute
Adds Facets support to a Search API Query.

Namespace

Drupal\jsonapi_search_api_facets\EventSubscriber

Code

protected function removeAliasConditions(ConditionGroupInterface $condition_group, array $aliases) {
  $conditions =& $condition_group
    ->getConditions();
  foreach ($conditions as $key => $condition) {
    if ($condition instanceof ConditionGroupInterface) {
      $this
        ->removeAliasConditions($condition, $aliases);
    }
    else {
      if (in_array($condition
        ->getField(), $aliases, TRUE)) {
        unset($conditions[$key]);
      }
    }
  }
}