You are here

function facetapi_get_block_info in Facet API 7

Same name and namespace in other branches
  1. 7.2 facetapi.block.inc \facetapi_get_block_info()

Helper function to get block info for all block-like realms.

Parameters

array $realm_names: An array of machine readable realm names blocks are being collected for.

Return value

array An array of block information.

See also

http://api.drupal.org/api/drupal/modules%21block%21block.api.php/functio...

1 call to facetapi_get_block_info()
facetapi_block_info in ./facetapi.block.inc
Implements hook_block_info().

File

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

Code

function facetapi_get_block_info(array $realm_names) {
  $blocks = array();
  foreach ($realm_names as $realm_name) {

    // Gets delta map, iterates over all enabled facets.
    $map = facetapi_get_delta_map();
    foreach (facetapi_get_searcher_info() as $searcher => $info) {

      // Gets cache settings for the searcher.
      $cache = facetapi_get_block_cache_setting($searcher, $realm_name);

      // Adds blocks for facets that are enabled or whose delta mapping is forced.
      foreach (facetapi_get_delta_map_queue($searcher, $realm_name) as $facet_name) {
        if ($facet = facetapi_facet_load($facet_name, $searcher)) {

          // Gets the delta from the delta map.
          $string = facetapi_build_delta($searcher, $realm_name, $facet_name);
          $delta = array_search($string, $map);

          // Builds the info. For non-block realm, append the realm name.
          $subject = 'Facet API: ' . $info['label'] . ' : ' . $facet['label'];
          if ('block' != $realm_name && ($realm = facetapi_realm_load($realm_name))) {
            $subject .= ' (' . $realm['label'] . ')';
          }

          // Defines the block.
          $blocks[$delta] = array(
            'info' => $subject,
            'cache' => $cache,
          );
        }
      }
    }
  }

  // Returns available blocks.
  return $blocks;
}