You are here

function global_filter_views_pre_view in Views Global Filter 6

Implements hook_views_pre_view().

This hook was implemented to ensure that a View timely receives its contextual argument (via $_SESSION['global_filter'][...]) even when it has a: a) page display, or b) block display that is rendered by core before the Global Filter block is. Yes this means that our tiny Global Filter block is rendered twice...so what?

Note: none if this is necessary if the view is an autocycle view. However, in this limited context we can't easily tell whether we're dealing with an auto-cycle view or not. Too bad, doesn't hurt.

File

./global_filter.module, line 557
global_filter.module

Code

function global_filter_views_pre_view($view, $display_id, $args) {
  if ($default_arguments = $view->display[$display_id]->display_options['arguments']) {
    $num_filter_blocks = variable_get('global_filter_num_filters', GLOBAL_FILTER_DEF_NUM_FILTERS);
    foreach ($default_arguments as $default_argument) {
      if ($default_argument['default_argument_type'] == 'global_filter_field') {
        for ($i = 1; $i <= $num_filter_blocks; $i++) {
          $filter_name = variable_get("global_filter_{$i}", NULL);
          if ($filter_name == $default_argument['field']) {
            global_filter_block_view("global_filter_{$i}");
            return;
          }
        }
      }
      foreach ($default_argument['default_argument_options'] as $key => $view_name) {
        for ($i = 1; $i <= $num_filter_blocks; $i++) {
          $filter_name = variable_get("global_filter_{$i}", NULL);
          if ($key == 'global_filter_view' && $filter_name == $view_name) {
            global_filter_block_view("global_filter_{$i}");
            return;
          }
        }
      }
    }
  }
}