You are here

function global_filter_set_form_on_session in Views Global Filter 8

Same name and namespace in other branches
  1. 7 global_filter.widgets.inc \global_filter_set_form_on_session()

Stashes the selected global filter value(s) in the user's session.

Parameters

array $form: the form

array $form_state: the form state

1 string reference to 'global_filter_set_form_on_session'
global_filter_finalise_form in ./global_filter.widgets.inc
Complete the form.

File

./global_filter.widgets.inc, line 483
global_filter.widgets.inc

Code

function global_filter_set_form_on_session($form, &$form_state) {
  foreach ($form_state['global_filters'] as $filter_key => $info) {
    $name = $info['name'];
    $widget = $info['widget'];
    if (strpos($widget, 'date') === 0) {

      // If successful this function returns a date range in the format
      // YYYY-MM-DD--YYYY-MM-DD, which is what Views' contextual filters need.
      $form_value = global_filter_extract_date_range($form_state, $filter_key);
    }
    elseif ($widget == 'range') {

      // Extract from 2 form fields an alphabetical or numeric range string, eg.
      // 'a--kz' or '1.5--3.5'
      // Only meaningful when used with the contextual_range_filter module.
      $form_value = global_filter_extract_alphanumeric_range($form_state, $name);
    }
    elseif ($widget == 'proximity') {
      $form_value = global_filter_extract_proximity($form_state);

      // Returns object with 'location', 'distance', 'latitude' and 'longitude'.
    }
    elseif (isset($form_state['values'][$name])) {

      // The rest of the widgets, both single and multi-choice (i.e array).
      $lang = isset($form_state['language']) ? $form_state['language'] : LANGUAGE_NONE;
      $form_value = global_filter_extract_values($form_state['values'][$name], $lang);
    }
    else {
      continue;
    }
    global_filter_set_on_session($name, $form_value);
  }

  // If rebuild==FALSE there will be an unnecessary drupal_goto(), so need to
  // force it not to redirect.
  // @see drupal_redirect_form()
  $form_state['rebuild'] = FALSE;
  $form_state['no_redirect'] = TRUE;
}