You are here

function facetapi_get_enabled_facets in Facet API 7

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

Returns all enabled facet definitions available to the searcher.

If a realm is passed, this function returns all facets enabled in the realm. If no realm is passed, this function returns all facets that are enabled in at least one realm.

Parameters

string $searcher: The machine readable name of the searcher.

string $realm_name: The machine readable name of the realm, pass NULL to return all facets that are enabled in at least one realm.

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.

4 calls to facetapi_get_enabled_facets()
FacetapiAdapter::getEnabledFacets in plugins/facetapi/adapter.inc
Returns enabled facets for the searcher associated with this adapter.
facetapi_facet_enabled in ./facetapi.module
Tests whether a single facet is enabled in a given realm.
facetapi_get_delta_map_queue in ./facetapi.block.inc
Returns facets that are enabled or whose delta mapping is forced.
facetapi_set_facet_status in ./facetapi.module
Enables or disables a facet for this page load only.
3 string references to 'facetapi_get_enabled_facets'
FacetapiTestCase::drupalPost in tests/facetapi.test
Overrides DrupalWebTestCase::drupalPost()
facetapi_save_facet_status in ./facetapi.module
Sets the facet status in a given realm, stores settings in the database.
facetapi_set_facet_status in ./facetapi.module
Enables or disables a facet for this page load only.

File

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

Code

function facetapi_get_enabled_facets($searcher, $realm_name = NULL) {
  $enabled_facets =& drupal_static(__FUNCTION__, array());
  $cid = $searcher . ':' . (string) $realm_name;
  if (!isset($enabled_facets[$cid])) {
    $facets = array();

    // Gets cached settings, finds enabled facets.
    $cached = facetapi_get_searcher_settings($searcher);
    foreach ($cached as $name => $settings) {
      $test_enabled = NULL === $realm_name || $realm_name == $settings->realm;
      if ($test_enabled && $settings->enabled) {
        $facets[$settings->facet] = $settings->facet;
      }
    }

    // Gets facet definitions for all enabled facets.
    $facet_info = facetapi_get_facet_info($searcher);
    $enabled_facets[$cid] = array_intersect_key($facet_info, $facets);

    // Alter enabled facets on the fly.
    drupal_alter('facetapi_enabled_facets', $enabled_facets[$cid], $searcher, $realm_name);
  }
  return $enabled_facets[$cid];
}