You are here

function facetapi_get_facet_info in Facet API 7

Same name and namespace in other branches
  1. 6.3 facetapi.module \facetapi_get_facet_info()
  2. 7.2 facetapi.module \facetapi_get_facet_info()

Returns all defined facet definitions available to the searcher.

Parameters

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

Return value

array An array of facet definitions. Each definition is an array keyed by the machine readable name of the facet. See the return value of the facetapi_facet_load() function for the structure of the definitions.

3 calls to facetapi_get_facet_info()
facetapi_facet_load in ./facetapi.module
Returns a facet definition.
facetapi_get_enabled_facets in ./facetapi.module
Returns all enabled facet definitions available to the searcher.
facetapi_realm_settings_form in ./facetapi.admin.inc
Form constructor for the realm settings form.

File

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

Code

function facetapi_get_facet_info($searcher) {
  $facet_info =& drupal_static(__FUNCTION__, array());

  // Gets facet info if we haven't gotten it already.
  if (!isset($facet_info[$searcher])) {

    // Builds cache ID.
    global $language;
    $cid = 'facetapi:facet_info:' . $searcher . ':' . $language->language;

    // Checks if our results are cached.
    $cache = cache_get($cid);
    if (!empty($cache->data)) {
      $facet_info[$searcher] = $cache->data;
    }
    else {
      $searcher_info = facetapi_get_searcher_info();
      $facet_info[$searcher] = array();

      // Invokes hook_facetapi_facet_info(), normalizes facets.
      foreach (module_implements('facetapi_facet_info') as $module) {
        $facets = call_user_func($module . '_facetapi_facet_info', $searcher_info[$searcher]);
        if (!$facets || !is_array($facets)) {
          $facets = array();
        }

        // Iterates over facet definitions, merges defaults.
        foreach ($facets as $facet_name => $info) {

          // @see http://drupal.org/node/1161434
          // Converts "query type" to an array and stores in "query types".
          // @todo Remove in later versions.
          if (isset($info['query type']) && !isset($info['query types'])) {
            $info['query types'] = array(
              $info['query type'],
            );
          }
          $facet_info[$searcher][$facet_name] = $info;
          $facet_info[$searcher][$facet_name] += array(
            'name' => $facet_name,
            'label' => $facet_name,
            'description' => '',
            'field' => $facet_name,
            'field alias' => isset($info['field']) ? $info['field'] : $facet_name,
            'field api name' => FALSE,
            'field api bundles' => array(),
            'query types' => array(
              'term',
            ),
            'alter callbacks' => array(),
            'dependency plugins' => array(),
            'default widget' => FALSE,
            'allowed operators' => array(
              FACETAPI_OPERATOR_AND => TRUE,
              FACETAPI_OPERATOR_OR => TRUE,
            ),
            'facet missing allowed' => FALSE,
            'facet mincount allowed' => FALSE,
            'weight' => 0,
            'map callback' => FALSE,
            'map options' => array(),
            '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,
              ),
            ),
          );

          // @see http://drupal.org/node/1161434
          // Makes sure old style "query type" is present.
          // @todo Remove in later versions.
          if (!isset($facet_info[$searcher][$facet_name]['query type'])) {
            $type = key($facet_info[$searcher][$facet_name]['query types']);
            $facet_info[$searcher][$facet_name]['type'] = $type;
          }
        }
      }

      // Invokes alter hook, sorts and returns.
      drupal_alter('facetapi_facet_info', $facet_info[$searcher], $searcher_info[$searcher]);
      array_walk($facet_info[$searcher], 'facetapi_map_assoc', 'field api bundles');
      uasort($facet_info[$searcher], 'drupal_sort_weight');

      // Caches the result.
      cache_set($cid, $facet_info[$searcher], 'cache', CACHE_TEMPORARY);
    }
  }
  return $facet_info[$searcher];
}