You are here

function global_filter_block_view in Views Global Filter 8

Same name and namespace in other branches
  1. 6 global_filter.blocks.inc \global_filter_block_view()
  2. 7 global_filter.blocks.inc \global_filter_block_view()

Implements hook_block_view().

$param $delta, index into the array $blocks defined in global_filter_block_info)(), e.g. 'global_filter_2'

1 call to global_filter_block_view()
global_filter_init in ./global_filter.module
Implements hook_init().

File

./global_filter.blocks.inc, line 329
global_filter.block.inc

Code

function global_filter_block_view($delta) {

  // In order to make sure that that the filter settings submitted via this
  // little block are received by the depending views before they're executed
  // this block may end up being requested twice: once in global_filter_init()
  // and once whenever core feels like it. Hence the caching.
  $blocks =& drupal_static(__FUNCTION__, array());
  if (empty($blocks[$delta])) {
    $usable_views = global_filter_get_view_names();
    $usable_fields = global_filter_get_usable_fields();
    $block_number = empty($delta) ? 1 : drupal_substr($delta, -1);

    // Set the block title, aka 'subject'.
    $blocks[$delta]['subject'] = '';
    foreach (global_filter_get_filters_for_block($block_number) as $filter) {
      $filter_name = $filter['name'];
      if ($filter['uses_view'] && isset($usable_views[$filter_name])) {
        $blocks[$delta]['subject'] .= drupal_substr($usable_views[$filter_name], 6);
      }
      elseif (isset($usable_fields[$filter_name])) {
        $label = $usable_fields[$filter_name];
        $pos_colon = strpos($label, ':');
        $pos_bracket = strrpos($label, '(');
        $blocks[$delta]['subject'] .= drupal_substr($label, $pos_colon + 2, $pos_bracket > $pos_colon ? $pos_bracket - $pos_colon - 3 : NULL);
      }
      $blocks[$delta]['subject'] .= ' ';
    }

    // With the block title set, now add all the filters for this block.
    $blocks[$delta]['content'] = drupal_get_form($delta);
  }
  return $blocks[$delta];
}