From cab08f9cfcfc5ff6faa30ca3ea09516e50b21da8 Mon Sep 17 00:00:00 2001
From: capynet <capy.net@gmail.com>
Date: Fri, 17 Jul 2015 15:05:10 +0200
Subject: [PATCH] geocoder-fix-computed-field-1679926-v1.2

---
 sites/all/modules/geocoder/geocoder.widget.inc                 | 6 +++---
 sites/all/modules/geocoder/plugins/geocoder_handler/google.inc | 8 ++++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/sites/all/modules/geocoder/geocoder.widget.inc b/sites/all/modules/geocoder/geocoder.widget.inc
index 3e42151..5292a14 100755
--- a/sites/all/modules/geocoder/geocoder.widget.inc
+++ b/sites/all/modules/geocoder/geocoder.widget.inc
@@ -230,7 +230,7 @@ function geocoder_widget_get_field_value($entity_type, $field_instance, $entity
     }
 
     // For entities being updated, determine if another geocode is necessary
-    if ($entity) {
+    if ($entity && $field_info['type'] != 'computed') {
       if (!empty($entity->original)) {
         //@@TODO: Deal with entity-properties (non-fields)
         //@@TODO: This isn't working with file fields. Should use some kind of lookup / map
@@ -271,10 +271,10 @@ function geocoder_widget_get_field_value($entity_type, $field_instance, $entity
         // Geocode any value from our source field.
         try {
           if (isset($handler_settings)) {
-            $geometry = call_user_func($handler['field_callback'], $field_info, $item, $handler_settings);
+            $geometry = call_user_func($handler['field_callback'], $field_info, $item, $handler_settings, $entity_type, $entity, $field_info, $field_instance, isset($entity->original->language) ? $entity->original->language : NULL, $source_field_values);
           }
           else {
-            $geometry = call_user_func($handler['field_callback'], $field_info, $item);
+            $geometry = call_user_func($handler['field_callback'], $field_info, $item, array(), $entity_type, $entity, $field_info, $field_instance, isset($entity->original->language) ? $entity->original->language : NULL, $source_field_values);
           }
           if ($geometry instanceof Geometry) {
             $geometries[] = $geometry;
diff --git a/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc b/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
index 5b1ddb9..f2ce3c6 100755
--- a/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
+++ b/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
@@ -121,8 +121,12 @@ function geocoder_google($address, $options = array()) {
   }
 }
 
-function geocoder_google_field($field, $field_item, $options = array()) {
-  if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
+function geocoder_google_field($field, $field_item, $options = array(), $entity_type, $entity, $field_info, $field_instance, $language , $source_field_values) {
+  if ($field['type'] == 'computed' && module_exists('computed_field')) {
+    _computed_field_compute_value($entity_type, $entity, $field_info, $field_instance, $language, $source_field_values);
+    return geocoder_google($source_field_values, $options);
+  }
+  if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary') {
     return geocoder_google($field_item['value'], $options);
   }
   if ($field['type'] == 'addressfield') {
-- 
2.1.4

