You are here

function location_views_form_alter in Location 5.3

Implementation of hook_form_alter().

File

contrib/location_views/location_views.module, line 976
Views-enables the location module.

Code

function location_views_form_alter($form_id, &$form) {

  // Fix the autocomplete path for the province field.
  // @@@ Unfortunately, views seems to cache the form contents.
  if ($form_id == 'views_filters') {
    $country = FALSE;
    foreach ($form['view']['#value']->filter as $k => $filter) {
      if ($filter['field'] == 'location.country') {
        $fv = views_get_filter_values();
        $country = $fv[$k]['filter'];
        if (!location_standardize_country_code($country)) {

          // Invalid country, fall back to default.
          $country = variable_get('location_default_country', 'us');
        }
        break;
      }
    }
    if ($country) {
      foreach ($form as $k => $field) {
        if (is_array($field) && isset($field['#location_views_province_field'])) {
          $form[$k]['#autocomplete_path'] = 'location/autocomplete/' . $country;
        }
      }
    }
  }
}