You are here

function facetapi_block_view in Facet API 6.3

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

Implements hook_block_view().

1 call to facetapi_block_view()
facetapi_block in ./facetapi.block.inc
@file Block realm code and hook implementations.

File

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

Code

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

  // Test block visibility if not already tested. This is necessary when using
  // modules such as Context that do not invoke hook_block_list_alter().
  if (!isset($parsed[$delta]) && !facetapi_check_block_visibility($delta)) {
    return;
  }
  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/settings/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],
    );

    // Drupal 6 needs direct output from a theme function so we will have to
    // iterate over the build array and output only what is needed.
    // Could use optimization
    $output = NULL;
    foreach (array_keys($builds[$group][$facet_name]) as $key) {
      if ($key[0] != '#') {
        $output = $builds[$group][$facet_name][$key];
        continue;
      }
    }
    return array(
      'subject' => theme('facetapi_title', $variables),
      'content' => $output,
    );
  }
}