This causes an empty map to be rendered (through OpenLayers) since the field is not empty, even though all its values are NULL.

When no geometries are returned, the field gets a LANGUAGE_NONE array with one value, NULL. Instead, the field should be an empty array in order for the field data to be deleted.

Attached is a patch to geocoder_field_attach_presave() in geocoder.widget.inc that solves this. I have had some successful testing, but I am not well versed with the entire widget. Is there a better way to do this? Does my method cause problems for other uses of the Geocoder widget?

Cheers,
Henry

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

henryblyth’s picture

#1588840: Geofield does not remove field_data record when all values are NULL using "Geocode from another field" contains some extra information regarding my mapping setup that brought this issue to my attention.

phayes’s picture

Status: Needs review » Fixed

Committed and fixed. Thank you!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

tomrishworth’s picture

I'm experiencing this issue, using the 7.x-1.2 version, which has the above patch included.

So I have a field called 'Address for Map' which geocoder uses. I'll add an address, and it'll geocode it fine, and display it on map. If I go back and delete the content in 'Address for Map' and save the node, the map will still display, showing the old point.

SeeSchloss’s picture

Version: 7.x-1.x-dev » 7.x-1.2
Status: Closed (fixed) » Needs review
FileSize
699 bytes

Reopening the issue since as tomnz said, the issue seems to exist in 1.2.
I didn't find a trace of this issue's patch in 1.2 code, here's a simple patch that seems to work for 1.2:

diff --git a/sites/all/modules/contrib/geocoder/geocoder.widget.inc b/sites/all/modules/contrib/geocoder/geocoder.widget.inc
index 3e42151..b9a7935 100644
--- a/sites/all/modules/contrib/geocoder/geocoder.widget.inc
+++ b/sites/all/modules/contrib/geocoder/geocoder.widget.inc
@@ -155,6 +155,8 @@ function geocoder_field_attach_presave($entity_type, $entity) {
     if ($field_instance['widget']['type'] === 'geocoder') {
       if (($field_value = geocoder_widget_get_field_value($entity_type, $field_instance, $entity)) !== FALSE) {
         $entity->{$field_instance['field_name']} = $field_value;
+      } else {
+        $entity->{$field_instance['field_name']} = array();
       }
     }
   }
ac’s picture

Status: Needs review » Reviewed & tested by the community

Can confirm this patch solves the issue of not removing previously geocoded points.

Simon Georges’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Simon Georges’s picture

Status: Closed (duplicate) » Fixed
Simon Georges’s picture

Status: Fixed » Closed (fixed)