Problem/Motivation
Formatter construct throws TypeError when map_provider_id is set but the map provider plugin is missing (submodule not enabled, or getMapProvider() returns null). Typical after 3.x upgrade / imported display config with google_maps while only base geolocation is on. Also crashes cron if that display is rendered.
TypeError: Cannot assign null to property Drupal\geolocation\Plugin\Field\FieldFormatter\GeolocationMapFormatterBase::$mapProvider of type Drupal\geolocation\MapProviderInterface in GeolocationMapFormatterBase->__construct() (line 70)
MapProviderManager::getMapProvider() returns ?MapProviderInterface. Constructor assigns it to a non-nullable property. settingsSummary() / viewElements() already treat it as optional ($this->mapProvider ?? NULL). Widget already uses ?MapProviderInterface $mapProvider = NULL.
Related, not duplicate: #3447082 (uninitialized property in summary when no provider id). This crash is assignment in __construct() when the id is set and the plugin is missing.
Steps to reproduce
- Geolocation 4.0.0. Enable
geolocationonly — notgeolocation_google_maps/ leaflet. - Geolocation field. Display formatter Geolocation Formatter - Map with
map_provider_id: google_maps. - View the entity (or cron if something renders that display).
Proposed resolution
protected ?MapProviderInterface $mapProvider = NULL;
Same as the widget. No other changes.
| Comment | File | Size | Author |
|---|---|---|---|
| geolocation-map-formatter-nullable-provider.patch | 688 bytes | luigisa |
Issue fork geolocation-3618463
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
christianadamski commentedThanks!