diff --git a/contrib/location_cck/location_cck.module b/contrib/location_cck/location_cck.module index e8352f4..ea8d380 100644 --- a/contrib/location_cck/location_cck.module +++ b/contrib/location_cck/location_cck.module @@ -428,10 +428,13 @@ function location_cck_field_widget_info() { function location_cck_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { if ($field['type'] == 'location') { $settings = isset($field['settings']['location_settings']) ? $field['settings']['location_settings'] : array(); + if (isset($form_state['values'])) { + $form_state_field_values = drupal_array_get_nested_value($form_state['values'], $element['#field_parents']); + } // Load location data for existing locations. - if ($form_state['rebuild'] && !empty($form_state['values'][$field['field_name']][$langcode][$delta])) { - $location = $form_state['values'][$field['field_name']][$langcode][$delta]; + if ($form_state['rebuild'] && !empty($form_state_field_values[$field['field_name']][$langcode][$delta])) { + $location = $form_state_field_values[$field['field_name']][$langcode][$delta]; } elseif (isset($items[$delta]['lid']) && $items[$delta]['lid']) { $location = location_load_location($items[$delta]['lid']); diff --git a/location.module b/location.module index 8613c28..f62a21c 100644 --- a/location.module +++ b/location.module @@ -922,7 +922,6 @@ function location_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) { '#attributes' => array('class' => array('location_auto_country')), '#ajax' => array( 'callback' => '_location_country_ajax_callback', - 'path' => 'system/ajax/' . implode('/', $settings['#parents']), 'wrapper' => 'location-dropdown-province-wrapper' . $wrapper_suffix, 'effect' => 'fade', ), @@ -1225,31 +1224,18 @@ function _location_autocomplete($country, $string = '') { * */ function _location_country_ajax_callback($form, $form_state) { - // The isset() checks, ideally, wouldn't ever have to happen because, ideally, - // this code would never get called, because, ideally, we wouldn't add an - // ajax call to the country field. Unfortunately, however, there's no easy - // way to check whether or not the province is being collected when putting - // together the country form element in location_locationapi() when that - // function is called with $op == 'field_expand' - if (arg(2) == 'locations' && isset($form['locations'][arg(3)]['province'])) { - return $form['locations'][arg(3)]['province']; - } - elseif (isset($form[arg(2)][arg(3)][arg(4)])) { - if (isset($form[arg(2)][arg(3)][arg(4)]['#entity_type']) && $form[arg(2)][arg(3)][arg( - 4 - )]['#entity_type'] == 'field_collection_item' - ) { - $selected_country_value = $form[arg(2)][arg(3)][arg(4)][arg(5)][arg(6)][arg(7)]['country']['#value']; - $form[arg(2)][arg(3)][arg(4)][arg(5)][arg(6)][arg(7)]['province']['#options'] = array( - '' => t('Select'), - 'xx' => t('NOT LISTED') - ) + location_get_provinces($selected_country_value); - - return $form[arg(2)][arg(3)][arg(4)][arg(5)][arg(6)][arg(7)]['province']; - } - - return $form[arg(2)][arg(3)][arg(4)]['province']; - } + // 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); + $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; } /**