In hook_entity_presave() a check is done to make sure the address has been updated before geocoding the address.

The check is done by comparing two address with $value !== $addresses[$delta] .

This can give lead to false positives when:

  • One array has empty entries not present in the other
  • The order of the entries is different

In neither case is this an actual change in the address.

I am experiencing this in combination with the migrate module. When importing and updating addresses using the migrate module the order is different and not all properties are present vs empty.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arnested created an issue. See original summary.

arnested’s picture

Status: Active » Needs review
FileSize
794 bytes
arnested’s picture

This time the patch with proper code style...

imclean’s picture

I'm having a related problem which could be resolved in this issue.

If there is an error with the initial geocoding due to incorrect API key, restrictions or network error, then the address may not change when it's edited. In this case, editing then saving entity won't try to geocode it again.

Changing the address then changing it back works around it, but it would be good to check if there are existing coordinates and always geocode if the location field is empty.

imclean’s picture

This adds the check for empty geolocation field.

imclean’s picture

Fix white space and add to comments.

arnested’s picture

@imclean, what if the address can't be encoded - not because of an error but because there is no coordinate to associate with the address?

Is there anyway we can distinct between "no coordinate" because "there actually is no coordinate" and "no coordinate because we haven't tried getting one / successfully got one yet"?

imclean’s picture

@arnested, I'm not sure that's likely to happen in this case. Address field requires a State/region and postcode at least. If Google can't find the specific address it'll respond with a point in the middle of the region. The only times we're not going to get that information is if the API key isn't valid or there's a communication problem.

arnested’s picture

@imclean, cool then I agree with your addition!

KarenS’s picture

"Address field requires a State/region and postcode at least. ", actually it does not. It is possible to configure it without those fields and that is the way I use it. So we should not make that assumption.

arnested’s picture

@KarenS, good to know.

But the patch I made in #3 should still be fine, then?

imclean’s picture

I can't remember now why I made that claim. Essentially my point was that if an address can't be encoded then Google still presents something.

imclean’s picture

@arnested, #3 doesn't take into account #4.

  • KarenS committed 5a9934e on 8.x-1.x authored by imclean
    Issue #2976496 by arnested, imclean: Detecting updated address in...
KarenS’s picture

Status: Needs review » Fixed

Looks good to me, committed!

Status: Fixed » Closed (fixed)

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