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

  1. Geolocation 4.0.0. Enable geolocation only — not geolocation_google_maps / leaflet.
  2. Geolocation field. Display formatter Geolocation Formatter - Map with map_provider_id: google_maps.
  3. View the entity (or cron if something renders that display).

Proposed resolution

protected ?MapProviderInterface $mapProvider = NULL;

Same as the widget. No other changes.

Command icon 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

luigisa created an issue. See original summary.

christianadamski’s picture

Status: Active » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • luigisa committed ecc178ee on 4.x
    Issue #3618463 by luigisa: Allow null map provider on...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.