We've had a few issues (#1648038: Issues with updating values through services being the most recent) where people have had trouble creating Geofield data programmatically. I suspect part of the issue is that on the field level, we expect an array of data that can be confusing to recreate. Geofield currently builds this data in the geofield_element_validate(), which handles all of our current widget needs, but leaves outside developers in the cold. :-(

We should move some of our processing code from geofield_element_validate() into geofield_field_presave(), so that we can auto-calculate data at the field level, which should allow us to require less data from developers.

Initially, I'm picturing that $items should either be an array with an 'input_format' item and a 'value' item, or just a raw string. If it's the array, then 'input_format' helps us decide how to process the data in value. If it's a raw string, then we try to decide if it's WKT, GeoJSON, etc. I'm definitely open to input here.

Credit goes to @phayes for the beginnings of this idea. I can't find the issue offhand where he first suggested something like this, but we should implement it anyway... :-)

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Brandonian’s picture

FileSize
61.31 KB

I'm 99% there, but I'm having trouble merging recent changes to the OL widget into my feature branch. Attached is my diff for others to play with.

Brandonian’s picture

FileSize
61.39 KB

Looking at the diff, I realized I had my branches backwards, which wouldn't apply for anybody... :-(

The real patch.

Brandonian’s picture

Status: Active » Fixed

I've committed changes that should make this easier to accomplish. When data is sent to be saved via the Field API, Geofield now accepts the following values...

  • An array with an 'input_format' value of GEOFIELD_INPUT_WKT, which processes the 'geom' value as wkt data.
  • An array with an 'input_format' value of GEOFIELD_INPUT_GEOJSON, which process the 'geom' value as geojson data.
  • An array with an 'input_format' value of GEOFIELD_INPUT_LAT_LON, which processes the 'lat' and 'lon' values as geo data.
  • An array with an 'input_format' value of GEOFIELD_INPUT_BOUNDS, which processes the 'top', 'right', 'bottom', and 'left' values as geo data.
  • A string that can be parsed by any of geoPHP's processors.

Status: Fixed » Closed (fixed)

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

sgp913’s picture

Hey Brandonian,

Thanks for the improvements. Any idea of how to structure this in a json put? I can't really figure out where the input_format value is supposed to go and if the lat/lon should be one value (lat,lon) or if they should be separated and how to structure it.

tribsel’s picture

re #5 this is how it works for me:
$new_value = array ('input_format' => GEOFIELD_INPUT_LAT_LON, 'geom' => array ( 'lat' => $latitude, 'lon' => $longitude));