You are here

function getlocations_fields_handler_filter_distance::value_form in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_fields/handlers/getlocations_fields_handler_filter_distance.inc \getlocations_fields_handler_filter_distance::value_form()

Options form subform for setting options.

This should be overridden by all child classes and it must define $form['value'].

Overrides views_handler_filter::value_form

See also

options_form()

File

modules/getlocations_fields/handlers/getlocations_fields_handler_filter_distance.inc, line 85
getlocations_fields_handler_filter_distance.inc @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Class

getlocations_fields_handler_filter_distance
General proximity filter for location latitude/longitude.

Code

function value_form(&$form, &$form_state) {
  parent::value_form($form, $form_state);
  $form['origin'] = getlocations_fields_element_origin($this->options['origin']);
  if (!empty($this->options['exposed'])) {
    $form['settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Form settings'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      // This will store all the defaults in one variable.
      '#tree' => TRUE,
    );
    $form['settings']['display_search_units'] = getlocations_element_map_checkbox(t('Display Search units dropdown'), isset($this->options['settings']['display_search_units']) ? $this->options['settings']['display_search_units'] : 1, t('Allow users to modify the search units.'));
    $form['settings']['display_search_distance'] = getlocations_element_map_checkbox(t('Display Search distance box'), isset($this->options['settings']['display_search_distance']) ? $this->options['settings']['display_search_distance'] : 1, t('Allow users to modify the search distance.'));

    // Google autocomplete
    $form['settings']['searchbox_size'] = getlocations_element_map_tf(t('Search box size'), isset($this->options['settings']['searchbox_size']) ? $this->options['settings']['searchbox_size'] : 60, t('The width of the search box.'), 5, 5, TRUE);
    $form['settings']['searchbox_size']['#dependency'] = array(
      'edit-options-origin' => array(
        'search',
      ),
    );

    // geocoder type
    $geocoder_default['geocoder_enable'] = isset($this->options['settings']['geocoder_enable']) ? $this->options['settings']['geocoder_enable'] : 0;
    $form['settings'] += getlocations_geocoder_form($geocoder_default);

    // country restriction
    $form['settings']['restrict_by_country'] = getlocations_element_map_checkbox(t('Restrict by country'), isset($this->options['settings']['restrict_by_country']) ? $this->options['settings']['restrict_by_country'] : 0, t('Restrict searches to the country set below. Works with Google Autocomplete.'));
    $form['settings']['restrict_by_country']['#dependency'] = array(
      'edit-options-origin' => array(
        'search',
      ),
    );
    $form['settings']['restrict_by_country']['#suffix'] = '<div id="getlocations_search_country">';
    $countries = getlocations_get_countries_list();
    $form['settings']['country'] = getlocations_element_dd(t('Search country'), isset($this->options['settings']['country']) ? $this->options['settings']['country'] : variable_get('site_default_country', ''), $countries);
    $form['settings']['country']['#dependency'] = array(
      'edit-options-origin' => array(
        'search',
      ),
    );
    $form['settings']['country']['#suffix'] = '</div>';
    $getlocations_fields_paths = getlocations_fields_paths_get();
    $getlocations_paths = getlocations_paths_get();
    $form['#attached']['js'] = array(
      $getlocations_fields_paths['getlocations_fields_search_views_path'] => array(
        'type' => 'file',
        'weight' => 20,
      ),
      $getlocations_paths['getlocations_geo_path'] => array(
        'type' => 'file',
        'weight' => 21,
      ),
    );
    if ($this->options['origin'] == 'search') {
      if (isset($this->options['settings'])) {
        $settings = array(
          'getlocations_fields_search_views' => array(
            'restrict_by_country' => isset($this->options['settings']['restrict_by_country']) ? $this->options['settings']['restrict_by_country'] : 0,
            'country' => isset($this->options['settings']['country']) ? $this->options['settings']['country'] : variable_get('site_default_country', ''),
            'geocoder_enable' => $geocoder_default['geocoder_enable'],
          ),
        );
        drupal_add_js($settings, 'setting');
      }
      $getlocations_defaults = getlocations_defaults();
      $getlocations_defaults['geocoder_enable'] = $geocoder_default['geocoder_enable'];
      getlocations_setup_js($getlocations_defaults, TRUE);
    }
  }
  if (!empty($form_state['exposed'])) {
    $identifier = $this->options['expose']['identifier'];
    if (!isset($form_state['input'][$identifier])) {

      // We need to pretend the user already inputted the defaults, because
      // fapi will malfunction otherwise.
      $form_state['input'][$identifier] = $this->value;
    }
  }
  $form['value'] = array(
    '#tree' => TRUE,
  );
  if ($this->options['origin'] == 'search') {
    $form['value']['search_field'] = getlocations_element_map_tf(t('Search'), '', '', isset($this->options['settings']['searchbox_size']) && $this->options['settings']['searchbox_size'] ? $this->options['settings']['searchbox_size'] : 60);
    $form['value']['search_field']['#dependency'] = array(
      'edit-options-origin' => array(
        'search',
      ),
    );
    $form['value']['search_field']['#attributes']['title'] = array(
      t('Start typing an address, then select from the dropdown'),
    );
  }
  $form['value']['latitude'] = getlocations_fields_element_latitude($this->value['latitude']);
  $form['value']['longitude'] = getlocations_fields_element_longitude($this->value['longitude']);
  if ($this->options['origin'] == 'search') {
    $form['value']['latitude']['#prefix'] = '<div class="js-hide">';
    $form['value']['longitude']['#suffix'] = '</div>';
  }

  #$form['value']['postal_code'] = getlocations_fields_element_postal_code($this->value['postal_code']);

  #$form['value']['country'] = getlocations_fields_element_country($this->value['country']);
  $form['value']['php_code'] = getlocations_fields_element_php_code($this->value['php_code']);

  // hide something in the DOM so that js knows this is a gps origin
  if ($this->options['origin'] == 'gps') {
    $form['value']['gps'] = array(
      '#type' => 'hidden',
      '#value' => 'origin',
      '#dependency' => array(
        'edit-options-origin' => array(
          'gps',
        ),
      ),
    );
  }
  list($nid_argument_options, $uid_argument_options, $tid_argument_options, $cid_argument_options) = getlocations_fields_views_proximity_get_argument_options($this->view);
  $loc_field_options = getlocations_fields_views_proximity_get_location_field_options();
  if ($nid_argument_options) {
    $form['value']['nid_arg'] = getlocations_fields_element_nid_arg($this->value['nid_arg'], $nid_argument_options);
    $form['value']['nid_loc_field'] = getlocations_fields_element_nid_loc_field($this->value['nid_loc_field'], $loc_field_options);
  }
  if ($uid_argument_options) {
    $form['value']['uid_arg'] = getlocations_fields_element_uid_arg($this->value['uid_arg'], $uid_argument_options);
    $form['value']['uid_loc_field'] = getlocations_fields_element_uid_loc_field($this->value['uid_loc_field'], $loc_field_options);
  }
  if ($tid_argument_options) {
    $form['value']['tid_arg'] = getlocations_fields_element_tid_arg($this->value['tid_arg'], $tid_argument_options);
    $form['value']['tid_loc_field'] = getlocations_fields_element_tid_loc_field($this->value['tid_loc_field'], $loc_field_options);
  }

  ## not tested yet
  if ($cid_argument_options) {
    $form['value']['cid_arg'] = getlocations_fields_element_cid_arg($this->value['cid_arg'], $cid_argument_options);
    $form['value']['cid_loc_field'] = getlocations_fields_element_cid_loc_field($this->value['cid_loc_field'], $loc_field_options);
  }
  $form['value']['search_units'] = getlocations_element_distance_unit($this->value['search_units']);
  $form['value']['search_distance'] = getlocations_element_search_distance($this->value['search_distance']);
  $form['value']['search_operator'] = array(
    '#type' => 'hidden',
    '#value' => $this->options['operator'],
    '#attributes' => array(
      'id' => array(
        'views_search_operator',
      ),
    ),
  );
}