You are here

function geocoder_field_widget_parse_addressfield in Geocoder 7.2

Geocoder Widget - Parse an address field.

File

modules/geocoder_field/geocoder_field.module, line 523

Code

function geocoder_field_widget_parse_addressfield($field_item) {
  $address = '';
  if (!empty($field_item['premise'])) {
    $address .= $field_item['premise'] . ',';
  }
  if (!empty($field_item['thoroughfare'])) {
    $address .= $field_item['thoroughfare'] . ',';
  }
  if (!empty($field_item['locality'])) {
    $address .= $field_item['locality'] . ',';
  }
  if (!empty($field_item['administrative_area'])) {
    $address .= $field_item['administrative_area'] . ',';
  }
  if (!empty($field_item['sub_administrative_area'])) {
    $address .= $field_item['sub_administrative_area'] . ',';
  }
  if (!empty($field_item['country'])) {

    // 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'] . ',';
  }
  if (!empty($field_item['postal_code'])) {
    $address .= $field_item['postal_code'] . ',';
  }
  $address = rtrim($address, ', ');
  return $address;
}