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

  1. Add a geolocation field to an entity type and create one entity that leaves the field empty.
  2. 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.
  3. 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.

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

loze created an issue. See original summary.

loze’s picture

Issue summary: View changes
loze’s picture

Issue summary: View changes

loze’s picture

Issue summary: View changes
loze’s picture

Issue summary: View changes
loze’s picture

Status: Active » Needs review

christianadamski made their first commit to this issue’s fork.

christianadamski’s picture

Status: Needs review » 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.

Status: Fixed » Closed (fixed)

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