Ajax error thrown if no providers are enabled

Created on 14 May 2024, 5 months ago
Updated 23 June 2024, 3 months ago

Problem/Motivation

Ajax error thrown and spinner just "hangs" without any other error indication when selecting Geolocation Formatter - Map without any Map provider.

Steps to reproduce

Install the Geolocation module but don't install any map providers. Then go to Manage display on the field and choose Geolocation Formatter - Map. The spinner comes on and a 500 error is thrown.
Error: Typed property Drupal\geolocation\Plugin\Field\FieldFormatter\GeolocationMapFormatterBase::$mapProvider must not be accessed before initialization in Drupal\geolocation\Plugin\Field\FieldFormatter\GeolocationMapFormatterBase->settingsSummary() (line 328 of /var/www/vhosts/staging.whalesafari.is/httpdocs/web/modules/contrib/geolocation/src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php).

Proposed resolution

Although a PEBKAC error, this needs to be handled more gracefully. The problem is that the summary function assumes that there is a $mapProvider initialised, but if there are no map providers installed, then it will not be initialised, hence the error.

Something like this would result in graceful display (Line 328 of GeolocationMapFormatterBase.php)

return (!isset($this->mapProvider))
      ? $summary
      : array_replace_recursive($summary, $this->mapProvider->getSettingsSummary($settings['map_provider_settings']));

Remaining tasks

User interface changes

The summary should display something like: "No map providers installed, please go "here" to install at least one.

API changes

None

Data model changes

None

🐛 Bug report
Status

Fixed

Version

4.0

Component

Javascript General / Frontend

Created by

🇮🇸Iceland drupalviking

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024