You are here

function mefibs_get_expected_items_for_exposed_form_block in MEFIBS - More exposed forms in blocks 7

Same name and namespace in other branches
  1. 8 mefibs.module \mefibs_get_expected_items_for_exposed_form_block()

Retrieve the elements that should go into an additional form.

Parameters

object $view: A fully loaded views object.

string $block_id: The internal machine name for the block.

Return value

array An array of view specific unique names of the elements for the additional form, keyed by type (filter, sort, other).

4 calls to mefibs_get_expected_items_for_exposed_form_block()
mefibs_block_view in ./mefibs.module
Implements hook_block_view().
mefibs_display_extender_plugin_blocks::options_form in ./mefibs_display_extender_plugin_blocks.inc
Provide a form to edit options for this plugin.
mefibs_hide_exposed_form_items in ./mefibs.module
Hide form elements that should not show up for the given block id.
mefibs_views_pre_build in ./mefibs.module
Implements hook_views_pre_build().

File

./mefibs.module, line 903
Primarily Drupal hooks and global API functions to manipulate views and to provide an additional block with an exposed filter form.

Code

function mefibs_get_expected_items_for_exposed_form_block($view, $block_id) {
  $mefibs = $view->display_handler
    ->get_option('mefibs');
  $display_id = $view->current_display;
  $elements = array(
    'filter' => array(),
    'sort' => array(),
    'other' => array(),
  );
  $exposed_items = mefibs_get_exposed_items($view);
  foreach (array(
    'filter',
    'other',
  ) as $type) {
    if (!isset($mefibs[$display_id][$type])) {
      continue;
    }
    foreach ($exposed_items[$type] as $key => $item) {

      // Filters can have exposed operators so in case this is an operator we
      // build a special base name without the attached '_op'.
      $is_operator = strrpos($item, '_op') === strlen($item) - 3;
      $base = $is_operator ? substr($item, 0, strlen($item) - 3) : $item;

      // Check for normal items and operators in special block.
      if (mefibs_item_visible($block_id, $mefibs, $display_id, $type, $item)) {
        $elements[$type][$key] = $item;
      }
    }
  }
  if (mefibs_sort_block_visible($block_id, $mefibs, $display_id)) {
    $elements['sort'] = $exposed_items['sort'];
  }
  $context = array(
    'view' => clone $view,
    'display_id' => $display_id,
    'block_id' => $block_id,
    'type' => 'expected_items',
  );
  drupal_alter('mefibs_elements', $elements, $context);
  return $elements;
}