You are here

function geocoder_field_widget_get_entity_field_value in Geocoder 7.2

Return the value for the given proxy-field for the given entity.

1 call to geocoder_field_widget_get_entity_field_value()
geocoder_field_widget_get_field_value in modules/geocoder_field/geocoder_field.module
Get a field's value based on geocoded data.

File

modules/geocoder_field/geocoder_field.module, line 266

Code

function geocoder_field_widget_get_entity_field_value($entity_type, $field_instance, $entity) {
  $field_name = is_array($field_instance['widget']['settings']['geocoder_field']) ? reset($field_instance['widget']['settings']['geocoder_field']) : $field_instance['widget']['settings']['geocoder_field'];
  $field_info = geocoder_field_widget_get_field_info($entity_type, $field_instance, $entity);

  // Get the source values
  if ($field_info['entity_key'] && $entity) {
    $source_field_values = array(
      array(
        'value' => $entity->{$field_name},
      ),
    );
  }
  else {
    if ($entity) {
      $wrapper = entity_metadata_wrapper($entity_type, $entity);
      $field_wrapper = $wrapper->{$field_name};
      $value = $field_wrapper
        ->value();
      $values = array_filter(is_array($value) && isset($value[0]) ? $value : array(
        $value,
      ));
      $source_field_values = array_map(function ($value) {
        if (is_array($value)) {

          // Clean up array from Addressfield, for diff.
          unset($value['element_key']);

          // Clean up array from Location, for diff.
          unset($value['location_settings'], $value['country_name'], $value['latitude'], $value['longitude'], $value['lid']);
          return array_filter($value);
        }
        return array(
          'value' => $value,
        );
      }, $values);
    }
    else {

      // We can't find the source values
      return FALSE;
    }
  }
  return $source_field_values;
}