Problem/Motivation
A view with a Geolocation proximity argument (geolocation_entity_argument) that receives a bare entity ID throws a fatal when that entity has no coordinates:
TypeError: Drupal\geolocation\Plugin\views\argument\EntityArgument::getParsedReferenceLocation(): Return value must be of type array, null returned in EntityArgument.php line 172
getParsedReferenceLocation() is declared : array. When the argument is a plain numeric ID it returns the result of getCoordinatesFromEntityId() directly, and that method is declared ?array and returns NULL when the entity does not exist or its geolocation field is empty. The other branch of the same method, for the 123<=5mi form, already guards this with if (empty($coordinates)) return [];. The bare ID branch is missing the same guard.
Steps to reproduce
- Add a geolocation field to an entity type and create one entity that leaves the field empty.
- Create a view of entities with that field, add the Geolocation proximity contextual filter, set "Geolocation Entity Argument Source" to that entity type and field.
- Load the view with the empty entity's ID as the argument.
Proposed resolution
Make getCoordinatesFromEntityId() return an empty array instead of NULL and type it : array. Both callers already treat an empty result as "no reference location" (the id<=distance branch checks empty($coordinates), and ProximityArgument checks isset($values['lat'])), so the view renders without the distance sort instead of fataling. The MR adds a kernel test to GeolocationViewsProximityByEntityTest with an origin node that has no coordinates; it fails with the TypeError above before the fix.
Issue fork geolocation-3621588
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 #2
loze commentedComment #3
loze commentedComment #5
loze commentedComment #6
loze commentedComment #7
loze commentedComment #9
christianadamski commentedThanks!