You are here

function tzfield_geofield_field_attach_presave in Time Zone Field 7

Implements hook_field_attach_presave().

File

tzfield_geofield/tzfield_geofield.module, line 52
Populate a time zone field from Geofield.

Code

function tzfield_geofield_field_attach_presave($entity_type, $entity) {
  list(, , $bundle_name) = entity_extract_ids($entity_type, $entity);
  foreach (field_info_instances($entity_type, $bundle_name) as $field_name => $field_instance) {
    if ($field_instance['widget']['type'] == 'tzfield_geofield') {
      $geofield_value = field_get_items($entity_type, $entity, $field_instance['widget']['settings']['geofield']);
      if ($geofield_value) {
        $entity->{$field_name}[LANGUAGE_NONE][0]['value'] = _tzfield_geofield_get_timezone($geofield_value[0]['lat'], $geofield_value[0]['lon']);
      }
      else {
        $entity->{$field_name} = array();
      }
    }
  }
}