Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This code in Geocoder::geocode()
is looping through an array of the form [$plugin_id => plugin_label
:
public function geocode($data, array $plugins, array $options = []) {
foreach ($plugins as $plugin_id) {
on systems that are case-sensitive, this results in $plugin_id
being set, for instance, to GoogleMaps
, resulting in this error:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "GoogleMaps" plugin does not exist.
Proposed resolution
Use array_keys
for the loop to get the actual plugin ID.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#12 | use-array-keys-for-provider-labels-2841914-06.patch | 1.97 KB | robertshell22 |
#5 | 2841914-05.patch | 1.31 KB | jhedstrom |
Comments
Comment #2
jhedstromComment #3
PolComment #4
jhedstromHmm, it isn't quite this simple of a fix. I think some code is calling
Geocode:geocoder()
with a simple numericly keyed array of plugin IDs, so with this patch, the result isComment #5
jhedstromThe interface docs for this method state:
so ones that are just calling it with the plugin ID should be fixed. Thus far I've found that
geocoder_field_entity_presave
was calling the method with a simple array of plugin IDs.This isn't the most elegant fix, but it gets the code working again...
Comment #6
jhedstromAnd this is the code that was calling with the full array (plugin_id => definition) in
AddressGeocodeFormatter
:Comment #8
PolThanks!
Comment #9
GlenAware CreditAttribution: GlenAware commentedWhile following the following example:
https://github.com/drupol/geocoder/blob/8.x-2.x/README.md
I get the following error:
The "0" plugin does not exist.
The following patch was applied.
modules/gecoder/src/Geocoder.php
From
To
The problem was resolved when I reverted the patch.
Output $options with patch:
Output $options without patch:
$options being supplied to geocode:
Tldr; Problem was resolved when reverting patch
Comment #10
ArnaudDabouis CreditAttribution: ArnaudDabouis commentedIs this the final API ? Because it breaks the latest dev of search_api_location for example. Should I provide a patch for that module to match the changes applied here ?
If so, I think the documentation of the GeocoderInterface, which mentions, about $plugins, "A list of plugin identifiers to use.", should be updated.
I'm personally reverting to previous commit for now.
Comment #12
robertshell22 CreditAttribution: robertshell22 commentedHere's a patch that applies to the latest 2.x-dev.
Comment #13
PolThanks !
Comment #14
itamair CreditAttribution: itamair as a volunteer commentedThe #12 patch introduces a great regression and everything breaks.
The committed #12 patch should be reverted immediately as not needed, and indeed harmful.
To verify just enable a Geocode operation on a field with just a Plugin.
The Drupal\geocoder\Geocoder geocode function will fail, as the $plugins already is an array of plugins machine names,
and array_keys($plugins) will return a list of not existing plugins.
So ... IMO we should really immediately revert the just committed #12 patch ...
Comment #15
itamair CreditAttribution: itamair as a volunteer commentedComment #16
itamair CreditAttribution: itamair as a volunteer commentedOnce the committed #12 patch has been reverted this issue might be closed anyway, because this sounds to me as an old-outdated issue.
(fixed by the last beta versions of the module)
Comment #18
itamair CreditAttribution: itamair as a volunteer commentedreverted the previously committed #12 patch.
Closing this one ...
Comment #19
itamair CreditAttribution: itamair as a volunteer commented