summaryrefslogtreecommitdiffstats
path: root/facets.module
blob: 2e89c4a675503cfc7967e5592fb53703390a3e38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

/**
 * @file
 * Contains facets.module
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\search_api\Query\QueryInterface;

/**
 * Implements hook_help().
 */
function facets_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the facets module.
    case 'help.page.facets':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Facets test') . '</p>';
      return $output;
    case 'facets.overview':
      return t('Below is a list of facets grouped by facetsources they are associated with. A facetsource is the instance where the facet does the actual filtering, e.g. a View on a Search API index.');
  }
}

/**
 * Implementation of hook_search_api_query_alter.
 *
 * @param \Drupal\search_api\Query\QueryInterface $query
 */
function facets_search_api_query_alter(QueryInterface &$query) {
  /** @var \Drupal\facets\FacetManager\DefaultFacetManager $facet_manager */
  $facet_manager = \Drupal::service('facets.manager');

  $search_id = $query->getOption('search id');

  // Add the active filters.
  $facet_manager->setFacetSourceId($search_id);
  $facet_manager->alterQuery($query);

}