You are here

function geocoder_widget_parse_addressfield in Geocoder 7

Geocoder Widget - Parse an address field.

8 calls to geocoder_widget_parse_addressfield()
geocoder_bing_field in plugins/geocoder_handler/bing.inc
Plugin callback.
geocoder_google_field in plugins/geocoder_handler/google.inc
Plugin callback.
geocoder_mapbox_field in plugins/geocoder_handler/mapbox.inc
Plugin callback.
geocoder_mapquest_nominatim_field in plugins/geocoder_handler/mapquest_nominatim.inc
Plugin callback.
geocoder_mapzen_field in plugins/geocoder_handler/mapzen.inc
Plugin callback.

... See full list

File

./geocoder.widget.inc, line 627
geocoder.widget.inc

Code

function geocoder_widget_parse_addressfield($field_item) {
  $address = array();
  $address[] = !empty($field_item['organization']) ? $field_item['organization'] : NULL;
  $address[] = !empty($field_item['premise']) ? $field_item['premise'] : NULL;
  $address[] = !empty($field_item['sub_premise']) ? $field_item['sub_premise'] : NULL;
  $address[] = !empty($field_item['thoroughfare']) ? $field_item['thoroughfare'] : NULL;
  $address[] = !empty($field_item['locality']) ? $field_item['locality'] : NULL;
  $address[] = !empty($field_item['postal_code']) ? $field_item['postal_code'] : NULL;
  if (!empty($field_item['country']) && !empty($field_item['administrative_area'])) {
    module_load_include('inc', 'addressfield', 'addressfield.administrative_areas');
    $areas = addressfield_get_administrative_areas($field_item['country']);
    $address[] = $areas[$field_item['administrative_area']];
  }
  else {
    $address[] = !empty($field_item['administrative_area']) ? $field_item['administrative_area'] : NULL;
  }
  $address[] = !empty($field_item['sub_administrative_area']) ? $field_item['sub_administrative_area'] : NULL;
  if (!empty($field_item['country'])) {
    if (module_exists('countries')) {
      $country = country_load($field_item['country']);
      $field_item['country'] = $country->name;
    }
    else {

      // Convert country code to country name.
      include_once DRUPAL_ROOT . '/includes/locale.inc';
      $countries = country_get_list();
      if (array_key_exists($field_item['country'], $countries)) {
        $field_item['country'] = $countries[$field_item['country']];
      }
    }
    $address[] = $field_item['country'];
  }
  return implode(',', array_filter($address));
}