Closed (fixed)
Project:
Geofield
Version:
10.3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
4 Mar 2026 at 10:04 UTC
Updated:
23 Mar 2026 at 17:50 UTC
Jump to comment: Most recent
Currently when exposing a Geofield via JSON:API you get the raw property values. Since Geofield is already capable of converting the geo data to GeoJSON it would be nice if there were a field enhancer to expose the GeoJSON output of the field via JSON:API.
-
Add a field enhancer.
-
-
-
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 #4
nickolajAdded a JSON:API Extras field enhancer plugin that converts Geofield WKT data to GeoJSON format on output and back to WKT on input. Uses the existing `geofield.geophp` service for geometry conversion.
Comment #5
itamair commentedThanks for providing all this.
Actually the MR !45 implementation of the GeofieldGeoJsonEnhancer looks correct, and implementing this feature request functionalities.
BUT the added Unit Tests (in geofield/tests/src/Unit/Plugin/jsonapi/FieldEnhancer/GeofieldGeoJsonEnhancerTest.php) are not passing,
... so this still look needing some refinement work.
PS: In relation to this review I created this JSON:API Extras Bug issue (and additional patch): https://www.drupal.org/project/jsonapi_extras/issues/3577834
Comment #6
namingthings commentedThank you @itamair for reviewing this.
The Unit test should now pass the pipeline.
I noticed that when passing a geojson array that either doesnt have a type key or an invalid type key that a warning is raised that cannot be caught.
Any thoughts on that?
Comment #7
itamair commented@namingthings thanks ...
I found and dedicated some time in better reviewing all this,
and provided some meaningful improvements:
Due the dependency from the from the jsonapi_extras module, etc. the Kernel test is a better way to test the GeofieldGeoJsonEnhancer.php.
This is also proven by the Kernel test from the jsonapi_extras module itself: jsonapi_extras/tests/src/Kernel/Plugin/jsonapi/FieldEnhancer/ListFieldEnhancerTest.php
Thus I removed the Unit Test (tests/src/Unit/Plugin/jsonapi/FieldEnhancer/GeofieldGeoJsonEnhancerTest.php) and your latest references / dependencies from the jsonapi_extras module in the Geofield code base,
and added the Kernel Test: tests/src/Kernel/Plugin/jsonapi/FieldEnhancer/GeofieldGeoJsonEnhancerTest.php with multiple additional tests.
Also I provided some small improvements to the GeofieldGeoJsonEnhancer FieldEnhancer definition itself.
Comment #8
itamair commentedComment #9
itamair commentedComment #10
itamair commentedWell, ok. This is interesting and logical. The Kernel test /tests/src/Kernel/Plugin/jsonapi/FieldEnhancer/GeofieldGeoJsonEnhancerTest.php
would fail now, due to this reported issue in the jsonapi_extras module: https://www.drupal.org/project/jsonapi_extras/issues/3577834
That is correct.
But in that case the Geofield module Kernel test on the GeofieldGeoJsonEnhancer will depend from the real functionality of the jsonapi_extras module as a whole (actually broken).
Thus, I moved back the Kernel GeofieldGeoJsonEnhancerTest tests in the Unit /tests/src/Unit/Plugin/jsonapi/FieldEnhancer/GeofieldGeoJsonEnhancerTest tests
This was a relevant headache ...
But now the coverage is wider and all test pass.
Comment #12
itamair commentedMR !45 merged into 10.3.x dev branch.
Thanks @namingthings. This will be parto of the next incoming Geofield release ...