You are here

function facetapi_block_view in Facet API 7

Same name and namespace in other branches
  1. 6.3 facetapi.block.inc \facetapi_block_view()
  2. 6 facetapi.widget.inc \facetapi_block_view()
  3. 7.2 facetapi.block.inc \facetapi_block_view()

Implements hook_block_view().

File

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

Code

function facetapi_block_view($delta = '') {
  $builds =& drupal_static(__FUNCTION__, array());
  $parsed =& drupal_static('facetapi_parsed_deltas', array());

  // Test block visibility if not already tested.
  if (!isset($parsed[$delta]) && !facetapi_check_block_visibility($delta)) {
    return array();
  }
  list($searcher, $realm_name, $facet_name) = $parsed[$delta];

  // Builds and caches the entire realm per searcher / realm combination.
  $group = $searcher . ':' . $realm_name;
  if (!isset($builds[$group])) {
    $builds[$group] = facetapi_build_realm($searcher, $realm_name);
  }

  // Returns the individual block.
  if (isset($builds[$group][$facet_name])) {

    // Adds contextual links.
    $builds[$group][$facet_name]['#contextual_links'] = array(
      'facetapi' => array(
        'admin/config/search/facetapi',
        array(
          $searcher,
          $realm_name,
          $facet_name,
        ),
      ),
    );

    // Returns the subject and content of the block.
    $variables = array(
      'title' => $builds[$group][$facet_name]['#title'],
      'facet' => $builds[$group][$facet_name],
    );
    return array(
      'subject' => theme('facetapi_title', $variables),
      'content' => $builds[$group][$facet_name],
    );
  }
}