You are here

function date_facets_associate_widget in Date Facets 7

Associates all date fields with the "date_range" query type.

Parameters

array &$facet_info: The facet definitions passed to hook_facetapi_facet_info_alter().

1 call to date_facets_associate_widget()
date_facets_facetapi_facet_info_alter in ./date_facets.module
Implements hook_facetapi_facet_info_alter().

File

./date_facets.module, line 36
Provides date range facets that are similar to implementations in major search engines.

Code

function date_facets_associate_widget(array &$facet_info) {
  foreach ($facet_info as $name => $info) {
    $query_types = array_flip($info['query types']);

    // The check on "field type" is specific to Search Api.
    $field_type = empty($info['field type']) ? '' : $info['field type'];

    // @todo check if there is a beter way to do this.
    if (isset($query_types['date']) || 'list<date>' == $field_type) {

      // Add the date_range to the query types
      $facet_info[$name]['query types'][] = DATE_FACETS_DATE_RANGE_QUERY_TYPE;

      // This widget needs a different way to set labels
      // so we add our own callback.
      $facet_info[$name]['map options']['value callback'] = '_date_facets_api_facet_create_label';
    }
  }
}