You are here

function addressfield_autocomplete_field_attach_presave in Addressfield Autocomplete 7

Implements hook_field_attach_presave().

Attaching the latitude and longitude values for geofield is done here.

File

./addressfield_autocomplete.module, line 525
The Addressfield Autocomplete module code.

Code

function addressfield_autocomplete_field_attach_presave($entity_type, $entity) {

  // Loop over any geofield using our geocode widget
  $entity_info = entity_get_info($entity_type);
  $bundle_name = empty($entity_info['entity keys']['bundle']) ? $entity_type : $entity->{$entity_info['entity keys']['bundle']};
  foreach (field_info_instances($entity_type, $bundle_name) as $instance) {
    if ($instance['widget']['type'] !== 'addressfield_autocomplete_latlng') {
      continue;
    }
    $values = _addressfield_autocomplete_widget_get_field_value($entity_type, $entity, $instance);
    if ($values) {
      $entity->{$instance['field_name']} = $values;
    }
  }
}