You are here

function current_search_block_view in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 contrib/current_search/current_search.block.inc \current_search_block_view()
  2. 7 contrib/current_search/current_search.block.inc \current_search_block_view()

Returns the content for a facet based on the delta.

1 call to current_search_block_view()
current_search_block in contrib/current_search/current_search.block.inc
Implements hook_block().

File

contrib/current_search/current_search.block.inc, line 120
Block hook implementations and block form alterations.

Code

function current_search_block_view($delta = '') {

  // Test block visibility if not already tested. This is necessary when using
  // modules such as Context that do not invoke hook_block_list_alter().
  $map =& ctools_static('current_search_delta_map');
  if (NULL === $map && !current_search_check_visibility($delta)) {
    return;
  }

  // Gets searcher from delta map.
  $searcher = $map[$delta];

  // Makes sure the adapter and configuration can be loaded.
  $adapter = facetapi_adapter_load($searcher);
  if ($adapter && ($config = ctools_export_crud_load('current_search', $delta))) {
    $content = '';

    // Iterates over configs and executes the plugins.
    foreach ($config->settings['items'] as $name => $settings) {
      if ($class = ctools_plugin_load_class('current_search', 'items', $settings['id'], 'handler')) {
        $plugin = new $class($name, $config);
        if ($return = $plugin
          ->execute($adapter)) {
          if (!empty($return['#theme'])) {
            $content .= theme($return['#theme'], $return['#items'], NULL, 'ul', $return['#attributes']);
          }
          else {
            $content .= $return['#value'];
          }
        }
      }
    }

    // Returns the block content.
    if (!empty($content)) {
      return array(
        'subject' => t('Current search'),
        'content' => $content,
      );
    }
  }
}