You are here

function _location_country_ajax_callback in Location 7.3

Same name and namespace in other branches
  1. 7.5 location.module \_location_country_ajax_callback()

AJAX callback for the Country select form, for cases where the province list.

Is also a select element and its options need to be updated. Uses the D7 Ajax Framework to do the select list updating. All we do here is select the element of the form that will be rebuilt.

1 string reference to '_location_country_ajax_callback'
location_locationapi in ./location.module
Implements hook_locationapi().

File

./location.module, line 1332
Location module main routines. An implementation of a universal API for location manipulation. Provides functions for postal_code proximity searching, deep-linking into online mapping services. Currently, some options are configured through an…

Code

function _location_country_ajax_callback($form, $form_state) {

  // Country select is the triggering element. Find the province field in the
  // same location fieldset.
  $country_field = $form_state['triggering_element'];
  $location_path = $form_state['triggering_element']['#array_parents'];
  array_pop($location_path);
  $location_field = drupal_array_get_nested_value($form, $location_path);
  if (isset($location_field['province'])) {
    $province = $location_field['province'];

    // Set new options from triggering element value.
    $province['#options'] = array(
      '' => t('Select'),
      'xx' => t('NOT LISTED'),
    ) + location_get_provinces($country_field['#value']);
    return $province;
  }
  return array();
}