You are here

function hook_facetapi_facet_info in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 facetapi.api.php \hook_facetapi_facet_info()
  2. 6 facetapi.api.inc \hook_facetapi_facet_info()
  3. 7 facetapi.api.php \hook_facetapi_facet_info()

Define all facets provided by the module.

Facets correspond with fields in the search index and are usually related to entity properties and fields. However, it is not a requirement that the source data be stored in Drupal. For example, if you are indexing external RSS feeds, facets can be defined that filter by the field in the index that stores the publication dates.

Parameters

array $searcher_info: The definition of the searcher that facets are being collected for.

Return value

array An associative array keyed by unique name of the facet. Each facet is an associative array containing:

  • name: Machine readable name of the facet.
  • label: Human readable name of the facet displayed in settings forms.
  • description: Description of the facet displayed in settings forms.
  • field: The field name used by the backend to store and retrieve data from the search index it is associated with. Defaults to the machine name of the facet.
  • field alias: The query string variable inside of the filter key used to pass the filter information through the query string. Defaults to the machine name of the facet.
  • field api name: (optional) The machine readable name of the Field API field data the facet is associated with, FALSE if it is not associated with a field.
  • field api bundles: (optional) An array of entity names that this field contains bundle information for. Defaults to an empty array.
  • query types: The query type plugins that that this facet supports. For example, numeric fields support "term" and "range_filter" queries.
  • alter callbacks: (optional) Callbacks that alter the initialized render array returned by the query type plugin. Defaults to an empty array.
  • dependency plugins: (optional) An array of dependency plugin IDs that are supported by this facet.
  • default widget: (optional) The widget plugin ID used if no plugin has been selected or the one selected is not valid. Defaults to FALSE which sets the default widget as the one defined by the realm.
  • allowed operators: (optional) An array keyed by operator constant to boolean values specifying whether the operator is supported. Defaults to an array containing:

  • facet missing allowed: (optional) Whether or not missing facets are allowed for this facet. Defaults to FALSE.
  • facet mincount allowed: (optional) Whether or not the facet supports the "minimum facet count" setting. Defaults to FALSE.
  • weight: (optional) The weight of the facet. Defaults to 0.
  • map callback: (optional) The callback used to map the raw values returned by the index to something human readable. Defaults to FALSE
  • map options: (optional) An array of options passed to the map callback, defaults to en empty array.
  • hierarchy callback: (optional) A callback that maps the parent / child relationships of the facet data, defaults to FALSE meaning the list is flat.
  • values callback: (optional) In instances where facet data is not returned by the backend, provide a list of values that can be used. Defaults to FALSE.
  • min callback: (optional) For facets containing ranges, a callback returning the minimum value in the index. Defaults to FALSE.
  • max callback: (optional) For facets containing ranges, a callback returning the maximum value in the index. Defaults to FALSE.
  • default sorts: (optional) An array of available sorts. Each item is an array containing two values, the first being the item being filtered on, the second being the SORT_* constant. Defaults to an array containing:

    • active: SORT_DESC
    • count: SORT_DESC
    • display: SORT_ASC
2 functions implement hook_facetapi_facet_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

facetapi_facetapi_facet_info in ./facetapi.facetapi.inc
Implements hook_facetapi_facet_info().
facetapi_test_facetapi_facet_info in tests/facetapi_test.module
Implements hook_facetapi_facet_info().
1 invocation of hook_facetapi_facet_info()
facetapi_get_facet_info in ./facetapi.module
Returns all defined facet definitions available to the searcher.

File

./facetapi.api.php, line 193
Hooks provided by the Facet API module.

Code

function hook_facetapi_facet_info(array $searcher_info) {
  $facets = array();

  // Facets are usually associated with the type of content stored in the index.
  if (isset($searcher_info['types']['my_type'])) {
    $facets['my_field'] = array(
      'name' => 'my_field',
      'label' => t('My field'),
      'description' => t('My field index some content we can facet by.'),
      'field' => 'my_field_index_field_name',
      'field alias' => 'my_alias',
      'field api name' => FALSE,
      'field api bundles' => array(),
      'query types' => array(
        'term',
        'date',
      ),
      'dependency plugins' => array(
        'role',
      ),
      'default widget' => 'links',
      'allowed operators' => array(
        FACETAPI_OPERATOR_AND => TRUE,
        FACETAPI_OPERATOR_OR => TRUE,
      ),
      'facet missing allowed' => FALSE,
      'facet mincount allowed' => FALSE,
      'weight' => 0,
      'map callback' => 'mymodule_map_my_field',
      'map options' => array(
        'field_option_1',
        'field_option_2',
      ),
      'hierarchy callback' => FALSE,
      'values callback' => FALSE,
      'min callback' => FALSE,
      'max callback' => FALSE,
      'default sorts' => array(
        array(
          'active',
          SORT_DESC,
        ),
        array(
          'count',
          SORT_DESC,
        ),
        array(
          'display',
          SORT_ASC,
        ),
      ),
    );
  }
  return $facets;
}