Photon provider is only compatible with certain lang codes

Created on 21 November 2023, 7 months ago
Updated 1 December 2023, 7 months ago

Problem/Motivation

I'm trying to use the Photon provider with a site whose primary (only) language is Danish (langcode da). When the query is sent to the Photon provider it triggers a 400 error due to the unsupported lang parameter being added.

Steps to reproduce

Set Danish as the language of a Drupal site
Configure a geofield with geocoder geocoding off an address field
Set up Photon as the provider
Submit a node form that triggers a geocode
Note the 400 error in the logs

Proposed resolution

In getHandlerWrapper the current language code is passed through to the StatefulGeocoder. I imagine this is useful for some providers but not necessarily all. It would be good to be able to alter what gets passed in or to have the option to ignore the language.

✨ Feature request
Status

Fixed

Version

4.0

Component

Code

Created by

🇮🇹Italy tanc Italy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tanc
  • 🇮🇹Italy itamair

    Thanks for reporting this @tanc. Your looks a good point ... I will inspect this better.
    Did you already looked if we could implement an hook altering what is passed to the provider, if not already there?

  • 🇳🇱Netherlands ekes

    I think there are two answers to this.

    One is that the photon provider should probably implement getHandlerWrapper() and check getCurrentLanguage() is in the list of known languages. If not is should fallback to a hard coded (or configurable) language.

    The second is you don't always want to geocode for the getCurrentLanguage, even more so as it defaults to Interface language. You might know what the target language that you want results in... the specific use case I have in mind here is address completion for entities, and translation based on the entity language.
    For this second more advanced case it would be helpful to be able to access the geocodeQuery method on the Provider. Then a Geocoder/Query (or specifically Gecoder/GeocodeQuery) can created by the caller withLocale() for that query. Doing this would also be an absolute bonus for geocoders that implement additional functionality (withBounds(), or non-standard parameters like the Nominatim provider's countrycode search restriction which requires withData() added).
    Thinking aloud. It would feel like path of least resistance, as there are already providers for Gecoder PHP and GeoPHP, additional interface that Provider's (the Geocoder PHP ones) could implement. Just need thinking about how it works with the caching and throttling (though it might be nice to move that to - Drupal custom - Middleware but as suggested in Geocoder PHP's docs -- it's probably possible to keep the present set-up, though reading the code I realize the caching currently doesn't take into account the locale changing?).

    Thoughts on both welcome. I kinda need the second so will be making some sort of patch I guess. If it's a good one that works for the module that'd be best!

    • itamair → committed 1f09cb97 on 8.x-3.x
      Implementation of Geocoder additional option for Locale code/id settings...
    • itamair → committed 85736b59 on 8.x-4.x
      Implementation of Geocoder additional option for Locale code/id settings...
  • Status changed to Fixed 7 months ago
  • 🇮🇹Italy itamair

    Thanks for your inputs. I dedicated much of my time this evening on this and just pushed an additional commit (both in
    8.x-4.x-dev and 8.x-3.x-dev) that is fully accomplishing this feature request.
    From the 8.x-3.37 and 8.x-4.12 releases a new Geocoder Additions Options tab is going to be available (with fairly detailed instructions) in every Geocoder Provider settings implementing the ProviderUsingHandlerWithAdapterBase (thus Photon included) where a specific Locale options can be set, to override the default behaviour matching the Current Interface language code/id, and that will be applied in the Geocoder Query withLocale() method ...
    (screenshot attached)

    My regards

  • Status changed to Active 7 months ago
  • 🇳🇱Netherlands ekes

    Ah cool I'll have a look. I've got some time I can spend on this (or something else) so that's a bonus.

  • Status changed to Fixed 7 months ago
  • 🇳🇱Netherlands ekes

    Oop cached value in the browser. I'll make a follow-up. The specific issue Tanc reported is fixed.

    • itamair → committed ea5fb2c5 on 8.x-4.x
      Better implementation of Geocoder additional option for Locale code/id...
    • itamair → committed 81b5a0b9 on 8.x-3.x
      Better implementation of Geocoder additional option for Locale code/id...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024