You are here

function facetapi_block_view in Facet API 6

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

Returns data for the "view" operation of hook_block().

Parameters

$delta: A string containing the identifier for the block.

Return value

An array containing the block subject and content.

1 call to facetapi_block_view()
facetapi_block in ./facetapi.module
Implementation of hook_block().

File

./facetapi.widget.inc, line 205
Widget callbacks and building functions.

Code

function facetapi_block_view($delta = '') {
  static $builds = array();

  // Bails if delta isn't mapped.
  $map = facetapi_delta_map_get();
  if (!isset($map[$delta])) {
    return array();
  }

  // Extracts the searcher, realm name, and facet name from $delta.
  list($searcher, $realm_name, $facet_name) = explode(':', $map[$delta]);
  $group = $searcher . ':' . $realm_name;

  // Bails if a search hasn't been executed.
  if (!($adapter = facetapi_adapter_load($searcher)) || !$adapter
    ->searchExecuted()) {
    return array();
  }

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

  // Returns the individual block.
  if (isset($builds[$group][$facet_name])) {
    return array(
      'subject' => NULL,
      'content' => drupal_render($builds[$group][$facet_name]),
    );
  }
  return array();
}