You are here

function _geocoder_field_geocoder_to_addressfield in Geocoder 7.2

Helper function. Transform an array from Geocoder PHP library into an array for AddressField module.

1 call to _geocoder_field_geocoder_to_addressfield()
geocoder_field_field_formatter_view in modules/geocoder_field/geocoder_field.module
Implements hook_field_formatter_view().

File

modules/geocoder_field/geocoder_field.module, line 829

Code

function _geocoder_field_geocoder_to_addressfield($geocoder, $field, $display, $instance) {
  $available_countries = _addressfield_country_options_list($field, $instance);
  $default_country = $display['settings']['default_country'];

  // Resolve the special site_default option.
  if ($default_country == 'site_default') {
    $default_country = variable_get('site_default_country', '');
  }

  // Fallback to the first country in the list if the default country is not
  // available, or is empty even though the field is required.
  $not_available = $default_country && !isset($available_countries[$default_country]);
  $empty_but_required = empty($default_country) && !empty($instance['required']);
  if ($not_available || $empty_but_required) {
    $default_country = key($available_countries);
  }
  $geocoder += array(
    'country' => $default_country,
    'name_line' => '',
    'first_name' => '',
    'last_name' => '',
    'organisation_name' => '',
    'administrative_area' => '',
    'sub_administrative_area' => '',
    'locality' => '',
    'dependent_locality' => '',
    'postal_code' => '',
    'thoroughfare' => '',
    'premise' => '',
    'sub_premise' => '',
    'data' => '',
  );
  $thoroughfare = array();
  if (isset($geocoder['streetNumber'])) {
    $thoroughfare[] = $geocoder['streetNumber'];
  }
  if (isset($geocoder['streetName'])) {
    $thoroughfare[] = $geocoder['streetName'];
  }
  $geocoder['thoroughfare'] = implode(', ', $thoroughfare);
  if (isset($geocoder['postalCode'])) {
    $geocoder['postal_code'] = $geocoder['postalCode'];
  }
  if (isset($geocoder['countryCode'])) {
    $geocoder['country'] = $geocoder['countryCode'];
  }
  return $geocoder;
}