You are here

function facetapi_check_block_visibility in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 facetapi.block.inc \facetapi_check_block_visibility()
  2. 7 facetapi.block.inc \facetapi_check_block_visibility()

Checks whether the block should be displayed.

In cases where modules like Context are being used, hook_block_list_alter() is not invoked and we get fatal errors. We have to test whether or not the hook has been invoked and call this function manually otherwise.

Parameters

$delta: The block delta.

Return value

A boolean flagging whether to display this block or not.

1 call to facetapi_check_block_visibility()
facetapi_block_view in ./facetapi.block.inc
Implements hook_block_view().

File

./facetapi.block.inc, line 149
Block realm code and hook implementations.

Code

function facetapi_check_block_visibility($delta) {
  $map = facetapi_get_delta_map();

  // Store parsed deltas so we only calculate once. This also lets us know
  // whether hook_block_list_alter() was called or not.
  $parsed =& drupal_static('facetapi_parsed_deltas', array());

  // Ensures the delta is mapped.
  if (!isset($map[$delta])) {
    $parsed[$delta] = FALSE;
    return FALSE;
  }

  // Parses the raw delta, extracts variables for code readability.
  $parsed[$delta] = facetapi_parse_delta($map[$delta]);
  list($searcher, $realm_name, $facet_name) = $parsed[$delta];

  // Checks whether block should be displayed.
  if (!facetapi_is_active_searcher($searcher)) {
    return FALSE;
  }
  if (!facetapi_facet_enabled($searcher, $realm_name, $facet_name)) {
    return FALSE;
  }
  if (!($adapter = facetapi_adapter_load($searcher))) {
    return FALSE;
  }
  if ($adapter
    ->suppressOutput($realm_name)) {
    return FALSE;
  }

  // We have facets!
  return TRUE;
}