You are here

function mefibs_set_default_values in MEFIBS - More exposed forms in blocks 7

Recursivly set correct default values for current filter set.

1 call to mefibs_set_default_values()
mefibs_form_views_exposed_form_alter in ./mefibs.module
Implements hook_form_FORM_ID_alter().

File

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

Code

function mefibs_set_default_values(&$form, $view, $block_id) {
  $current_filters = array();
  if (isset($_SESSION['mefibs'][$view->name][$view->current_display]['filters'])) {
    $current_filters = $_SESSION['mefibs'][$view->name][$view->current_display]['filters'];
  }
  foreach (element_children($form) as $element) {
    if (isset($current_filters[$element])) {
      $form[$element]['#default_value'] = $current_filters[$element];

      // This is a first quick draft for composed filter elements like
      // "in between" filters.
      if (is_array($current_filters[$element])) {
        foreach ($current_filters[$element] as $key => $value) {
          if (isset($form[$element][$key]) && isset($form[$element][$key]['#type'])) {
            $form[$element][$key]['#default_value'] = $value;
          }
        }
      }
    }
    if (count(element_children($form[$element]))) {
      mefibs_set_default_values($form[$element], $view, $block_id);
    }
  }
}