From 43ea02aee029700b5133d5899b32ba5535212d19 Mon Sep 17 00:00:00 2001
From: Rob Costello <rob.costello@wiredcanvas.com>
Date: Wed, 25 Nov 2015 12:52:09 +0000
Subject: [PATCH] Added geocoder patch from here and updated slightly:
 https://www.drupal.org/node/1679926

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

diff --git a/docroot/sites/all/modules/geocoder/geocoder.widget.inc b/docroot/sites/all/modules/geocoder/geocoder.widget.inc
index 3e42151..5292a14 100644
--- a/docroot/sites/all/modules/geocoder/geocoder.widget.inc
+++ b/docroot/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/docroot/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc b/docroot/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
index 5b1ddb9..fc1596d 100755
--- a/docroot/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
+++ b/docroot/sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
@@ -121,8 +121,20 @@ 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);
+    // If source computed values are arrays, just take the first one.
+    // @@Todo: how to deal with multi-value computed fields.
+    if (gettype($source_field_values) === 'array') {
+    	$value = $source_field_values[0]['value'];
+    }
+    else {
+    	$value = $source_field_values;
+    }
+    return geocoder_google($value, $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') {
-- 
1.8.4.2

