You are here

function location_views_handler_filter_proximity::exposed_form in Location 7.4

Same name and namespace in other branches
  1. 6.3 handlers/location_views_handler_filter_proximity.inc \location_views_handler_filter_proximity::exposed_form()
  2. 7.5 handlers/location_views_handler_filter_proximity.inc \location_views_handler_filter_proximity::exposed_form()
  3. 7.3 handlers/location_views_handler_filter_proximity.inc \location_views_handler_filter_proximity::exposed_form()

Render our chunk of the exposed filter form when selecting.

You can override this if it doesn't do what you expect.

Overrides views_handler_filter::exposed_form

File

handlers/location_views_handler_filter_proximity.inc, line 216

Class

location_views_handler_filter_proximity
General proximity filter for location latitude/longitude.

Code

function exposed_form(&$form, &$form_state) {
  parent::exposed_form($form, $form_state);
  $key = $this->options['expose']['identifier'];
  $origin = $this->options['origin'];

  // Strip dependencies off on exposed form.
  foreach (element_children($form[$key]) as $el) {
    if (!empty($form[$key][$el]['#dependency'])) {
      $form[$key][$el]['#dependency'] = array();
    }
  }
  if ($origin == 'latlon_gmap' && module_exists('gmap')) {

    // Bad things happen if we try to show a gmap in the views live preview.
    if ($form_state['post']['live_preview']) {
      $form[$key]['proximity_map'] = array(
        '#value' => t('Gmap location selection is not available during live preview.'),
        '#weight' => 0,
      );
    }
    else {
      $form[$key]['proximity_map'] = array(
        '#value' => gmap_set_location($this->options['expose']['gmap_macro'], $form[$key], array(
          'latitude' => 'latitude',
          'longitude' => 'longitude',
        )),
        '#weight' => 0,
      );
    }
  }
  else {
    if (($origin == 'user' || $origin == 'hybrid') && $this->options['expose']['user_location_choose']) {
      global $user;
      $user_locations = isset($user->locations) ? $user->locations : location_load_locations($user->uid, 'uid');
      $location_options = array();
      if (!empty($user_locations)) {
        foreach ($user_locations as $i => $location) {
          if (isset($location['latitude']) && isset($location['longitude'])) {
            if (!empty($location['name'])) {
              $location_options[$i] = t(check_plain($location['name']));
            }
            else {
              $location_options[$i] = t('Location #@num', array(
                '@num' => $i + 1,
              ));
            }
          }
        }
      }
      $form[$key]['user_location_delta'] = array(
        '#type' => 'select',
        '#title' => t('Location'),
        '#options' => $location_options,
        '#description' => t('Select which of your locations to use.'),
        '#weight' => 0,
      );
    }
  }

  // Remove unneeded fields when exposing the form.
  // It's shorter than redefining value_form.
  if ($origin != 'static' && $origin != 'latlon_gmap') {
    unset($form[$key]['latitude']);
    unset($form[$key]['longitude']);
  }
  if ($origin != 'postal' && $origin != 'postal_default') {
    unset($form[$key]['postal_code']);
  }
  if ($origin != 'postal') {
    unset($form[$key]['country']);
  }

  // And we definitely do not want to expose the php code option when exposing the filter
  unset($form[$key]['php_code']);

  // The nid/uid arg options are not useful on an exposed form.
  unset($form[$key]['nid_arg']);
  unset($form[$key]['nid_loc_field']);
  unset($form[$key]['uid_arg']);
  unset($form['origin']);
}