You are here

function facetapi_facets_get in Facet API 6

Invokes hook_facetapi_facet_info(), returns all defined facets.

Parameters

$searcher: A string containing the machine readable name of the searcher module.

$type: A string containing the type of content $searcher indexes.

Return value

An array containing the facet arrays, FALSE on errors.

3 calls to facetapi_facets_get()
facetapi_admin_settings_form in ./facetapi.admin.inc
Administrative settings for Search Lucene Facets.
facetapi_enabled_facets_get in ./facetapi.module
Returns facets enabled in a given realm. If the realm name is NULL, all facets that are enabled in at least one realm will be returned.
facetapi_facet_load in ./facetapi.module
Loads a single facet definition.

File

./facetapi.module, line 369
An abstracted facet API that can be used by various search backens.

Code

function facetapi_facets_get($searcher, $type) {
  $facets = array();

  // Gets facets from hooks and the modules the facets are defined in.
  foreach (module_implements('facetapi_facet_info') as $module) {
    $module_facets = module_invoke($module, 'facetapi_facet_info', $searcher, $type);
    foreach ((array) $module_facets as $facet_name => $facet) {

      // Builds array of default values.
      $defaults = array(
        'name' => $facet_name,
        'title' => $facet_name,
        'description' => '',
        'field' => $facet_name,
        'field alias' => isset($facet['field']) ? $facet['field'] : $facet_name,
        'query type' => 'term',
        'data group' => FALSE,
        'widget requirements' => array(),
        'default widgets' => array(),
        'weight' => 0,
        'map callback' => FALSE,
        'hierarchy callback' => FALSE,
        'values callback' => FALSE,
        'min callback' => FALSE,
        'max callback' => FALSE,
        'file' => '',
        'file path' => drupal_get_path('module', $module),
        'default sorts' => array(
          array(
            'active',
            SORT_DESC,
          ),
          array(
            'count',
            SORT_DESC,
          ),
          array(
            'display',
            SORT_ASC,
          ),
        ),
      );

      // Merges facet definition into defaults.
      $facets[$facet_name] = array_merge($defaults, $facet);

      // Checks whether facet is flat or hierarchical, adds to requirements.
      if (!$facets[$facet_name]['hierarchy callback']) {
        $facets[$facet_name]['widget requirements'][] = 'flat';
      }
      else {
        $facets[$facet_name]['widget requirements'][] = 'hierarchical';
      }
    }

    // Invokes alter hook to allow modules to modify facet definitions.
    drupal_alter('facetapi_facet_info', $facets, $searcher, $type);
  }

  // Sorts facets by weight, returns facets.
  uasort($facets, 'facetapi_sort_weight');
  return $facets;
}