You are here

function geocoder_widget_get_entity_field_value in Geocoder 7

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

1 call to geocoder_widget_get_entity_field_value()
geocoder_widget_get_field_value in ./geocoder.widget.inc
Get a field's value based on geocoded data.

File

./geocoder.widget.inc, line 352
geocoder.widget.inc

Code

function geocoder_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_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},
      ),
    );
  }
  elseif ($entity) {
    $wrapper = entity_metadata_wrapper($entity_type, $entity);
    if (!empty($wrapper
      ->value()->{$field_name})) {
      $field_wrapper = $wrapper
        ->value()->{$field_name};
    }
    else {
      return FALSE;
    }
    $langcode = field_language($entity_type, $entity, $field_name);
    $value = $field_wrapper[$langcode];
    $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;
}