Location cannot be re-geocoded after update in entity browser

Created on 13 October 2024, 8 months ago

Problem/Motivation

Discovered in Localgov Drupal directories, though I think this will occur anywhere using an entity browser to select geo entities where the Geo could be edited inside the entity browser. It does not occur when editing the Geo_entity under admin -> content -> locations / geos.

Original issue on See: https://github.com/localgovdrupal/localgov_geo/issues/133

Create a new directory venue with a brand new geo entity as a location. This should geocode the map pin.
Then edit said directory venue, and edit the location (not delete and replace). Clear out the address and try to add a new one. Whilst the autocomplete does replace it, the leaflet map pin and lat / lon fields are not updated.
I have seen this with both directories and events, and with fresh localgov drupal install and BHCC code base.
Happens regardless on if using leaflet or geofield_map for the map pin.

This has been seen in Directories and Events, but works fine when editing the geo_entity directly.
Posting here whilst investigating if it is a specific configuration issue with Directories and events.

Steps to reproduce

See linked Github issue above.

Proposed resolution

I managed to trace this to js/geocode-leaflet.js and the corresponding js/geocode-geofield.js. They are trying to attach javascript to a form with id geo-entity-address-edit-form which will have been changed to add a unique string at the end on subsequent loads eg. geo-entity-address-edit-form-uqlfl1mbwkm.
once('geoEntityGeocodeLeaflet', document.getElementById(formId)).forEach(function (form) {
This is fetching the formId from drupalSettings.geoEntityGeocode.leaflet which gives

{geo-entity-address-edit-form: 'leaflet-map-widget-geo-entity-address-35-location--6NyaxaYSeuE'}

It looks like the key needs to updated like the value side to reflect the unique ID of the form.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom andybroomfield

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

Merge Requests

Comments & Activities

  • Issue created by @andybroomfield
  • 🇬🇧United Kingdom andybroomfield

    Changing
    once('geoEntityGeocodeLeaflet', document.getElementById(formId)).forEach(function (form) {
    to
    once('geoEntityGeocodeLeaflet', document.querySelectorAll('form[id^="' + formId + '"]')).forEach(function (form) {
    works. Might not be the most performant though.

  • 🇳🇱Netherlands ekes

    I'm just trying to recreate this. Are there some steps I could follow?

  • 🇬🇧United Kingdom andybroomfield

    See the linked Github issue above:

    1. Create a new directory venue with a brand new geo entity as a location. This should geocode the map pin.
    2. Then edit said directory venue, and edit the location (not delete and replace).
    3. Clear out the address and try to add a new one. Whilst the autocomplete does replace it, the leaflet map pin and lat / lon fields are not updated.
  • First commit to issue fork.
  • Pipeline finished with Failed
    19 days ago
    Total: 159s
    #499009
  • 🇬🇧United Kingdom hannahdigidev

    Opened merge request with patch.

  • 🇬🇧United Kingdom andybroomfield

    Not sure why the tests are failing for @hannahdigidev MR. I've run the test suite locally with PHP 8.3 and 8.4 and they all pass.

    % /opt/homebrew/opt/php@8.4/bin/php vendor/bin/phpunit web/modules/contrib/geo_entity --testdox
    PHPUnit 9.6.23 by Sebastian Bergmann and contributors.

    Testing [redacted]/web/modules/contrib/geo_entity
    Address Forms (Drupal\Tests\geo_entity_address\Functional\AddressForms)
    ✔ Crud

    Geonames Service (Drupal\Tests\geo_entity_tz\Unit\GeonamesService)
    ✔ Config missing
    ✔ Error
    ✔ Response

    Geo Bundle Creation (Drupal\Tests\geo_entity\Functional\GeoBundleCreation)
    ✔ Media type creation form

    Geo Overview Access (Drupal\Tests\geo_entity\Functional\GeoOverviewAccess)
    ✔ Overview page access

    Time: 00:19.076, Memory: 22.48 MB

    OK (6 tests, 51 assertions)

    Remaining self deprecation notices (14)

    2x: \Drupal\Core\Render\Element\FormElement::processGroup() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Render\Element\FormElementBase::processGroup() instead. See https://www.drupal.org/node/3436275
    2x in AddressFormsTest::testCrud from Drupal\Tests\geo_entity_address\Functional

    2x: \Drupal\Core\Render\Element\FormElement::valueCallback() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Render\Element\FormElementBase::valueCallback() instead. See https://www.drupal.org/node/3436275
    2x in AddressFormsTest::testCrud from Drupal\Tests\geo_entity_address\Functional

    1x: \Drupal\Core\Render\Element\FormElement::preRenderGroup() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Render\Element\FormElementBase::preRenderGroup() instead. See https://www.drupal.org/node/3436275
    1x in AddressFormsTest::testCrud from Drupal\Tests\geo_entity_address\Functional

    1x: Renderer::renderPlain() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Instead, you should use ::renderInIsolation(). See https://www.drupal.org/node/3407994
    1x in AddressFormsTest::testCrud from Drupal\Tests\geo_entity_address\Functional

    1x: Drupal\geo_entity_tz\GeonamesTimezone::getTimezone(): Implicitly marking parameter $radius as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezone::timezoneRequest(): Implicitly marking parameter $radius as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezone::timezoneRequest(): Implicitly marking parameter $lang as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezone::timezoneRequest(): Implicitly marking parameter $date as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezoneInterface::getTimezone(): Implicitly marking parameter $radius as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezoneInterface::timezoneRequest(): Implicitly marking parameter $radius as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezoneInterface::timezoneRequest(): Implicitly marking parameter $lang as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

    1x: Drupal\geo_entity_tz\GeonamesTimezoneInterface::timezoneRequest(): Implicitly marking parameter $date as nullable is deprecated, the explicit nullable type must be used instead
    1x in GeonamesServiceTest::testConfigMissing from Drupal\Tests\geo_entity_tz\Unit

  • 🇳🇱Netherlands ekes
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024