While attempting to geocode multiple values from an addressfield set to accept unlimited number of values, I noticed the $source_field_values array passed to geocoder_widget_get_field_value() has an extra item that should be ignored. Here's an example of what $source_field_values looks like after I've entered 1 address in the form:
array(
[0] =>
array(
['element_key'] => 'node|og_blog_post|field_postal_address|und|0'
['thoroughfare'] => 'Cape Town'
['premise'] =>
['postal_code'] =>
['locality'] =>
['administrative_area'] =>
['country'] => 'ZA'
['_weight'] => 0
)
['add_more'] => 'Add another item'
)
I'm using Google Geocoder. Later on, geocoder_google_field() geocodes both. The second value is not needed. I've attached a patch to address this. Some of the other supported field types, e.g. location, might have a similar issue if multiple values are allowed. I've not checked.
addressfield 7.x-1.0-beta3
geocoder 7.x-1.1+15-dev
geofield 7.x-2.x-dev
openlayers 7.x-2.0-beta1+53-dev
Comment | File | Size | Author |
---|---|---|---|
#2 | geocoder-invalid_source_values-1707842-1.patch | 761 bytes | netbek |
geocoder-invalid-source-values.diff | 767 bytes | netbek | |
Comments
Comment #1
phayes CreditAttribution: phayes commentedWould it instead be valid to check to make sure the key is numeric? Would that work across all field types do you think?
Comment #2
netbek CreditAttribution: netbek commentedYes, checking for numeric keys should do. I haven't come across non-numeric deltas. Patch attached. Changes are after field_get_items() in case field has no items.
I've tried it with taxonomy terms, addressfield and location fields set to single and multiple values. Apart from the "Add another item" button, multiple value addressfield and location also add an "empty" value when one edits a node after saving it. The "empty" value only has its country selected. It will be geocoded too if one is using the OpenLayers Map widget with Geofield.
Screenshot above to illustrate - first location "Home" was added when node created, second location with default country selected appears when node is edited.
Only ways I can see how one could avoid geocoding the "empty" value with the OL map widget is to:
a) Add checkboxes to each value to allow the user to choose what to geocode. That adds a fair chunk of complexity, though. It's quicker to remove the unnecessary point from the map.
b) Add a standard way to deal with multiple value fields in core #1038316: Allow for deletion of a single value of a multiple value field, so that user can remove unnecessary locations/addresses before clicking "Find using ... field" button.
Comment #3
phayes CreditAttribution: phayes commentedLooks good. I'll merge this in when I get the chance.
Comment #4
phayes CreditAttribution: phayes commentedCommitted