You are here

function geocoder_field_attach_load in Geocoder 7

Implements hook_field_attach_load().

File

./geocoder.widget.inc, line 265
geocoder.widget.inc

Code

function geocoder_field_attach_load($entity_type, $entities, $age, $options) {

  // Loop over all the entities looking for entities with geocoder field.
  foreach ($entities as &$entity) {
    list(, , $bundle) = entity_extract_ids($entity_type, $entity);

    // Examine every geocoder field instance attached to this entity's bundle.
    foreach (field_info_instances($entity_type, $bundle) as $field_name => $instance) {
      if ($instance['widget']['type'] === 'geocoder' && !empty($instance['widget']['settings']['latlng_override']) && ($geocoded_value = geocoder_widget_get_field_value($entity_type, $instance, $entity))) {
        foreach ($entity->{$field_name} as $langcode => $items) {
          foreach ($items as $delta => $item) {
            if (round($item['lat'], 3) !== round($geocoded_value[$langcode][$delta]['lat'], 3) || round($item['lon'], 3) !== round($geocoded_value[$langcode][$delta]['lon'], 3)) {
              $entity->geocoder_overridden[$field_name][$langcode][$delta] = TRUE;
            }
          }
        }
      }
    }
  }
}