PHP8: fatal error when viewing event info page with OpenStreetMaps as mapping provider and a location with no geocode
Replication Steps
- On PHP 8.1, configure Civi with OpenStreetMaps as the Mapping Provider, but no (working) geocoding provider. On a civibuild site, setting Geocoding Provider to Google will do the trick.
- Edit an event to create a new address (which won't have a geocode since geocoding is disabled).
- Configure the event to show a map.
- Go to the Event Info page.
Expected Result
No map, because no geocode.
Actual Result
Fatal Error.
Comments
This happens because of this line in <civiroot>/templates/CRM/Contact/Form/Task/Map/OpenStreetMaps.tpl
:
{if count($locations) gt 1}
It expects $locations
to always be set.
I imagine an alternative solution is to add an isset()
to the template. I can do the other fix if preferred though.