You are here

function geocoder_field_field_attach_presave in Geocoder 7.2

Implements hook_field_attach_presave().

Geocoding for the geocoder widget is done here to ensure that only validated and fully processed fields values are accessed.

File

modules/geocoder_field/geocoder_field.module, line 227

Code

function geocoder_field_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 $field_instance) {
    if ($field_instance['widget']['type'] === 'geocoder') {
      if (($field_value = geocoder_field_widget_get_field_value($entity_type, $field_instance, $entity)) !== FALSE) {
        $entity->{$field_instance['field_name']} = $field_value;
      }
    }
  }
}