In my opinion it's a matter of some missing "['geom']" in function geofield_field_widget_form.
Lines 153-158 should be:
153 if (isset($items[$delta]['geom']['lat'])) {
154 $latlon_value['lat'] = floatval($items[$delta]['geom']['lat']);
155 }
156 if (isset($items[$delta]['geom']['lon'])) {
157 $latlon_value['lon'] = floatval($items[$delta]['geom']['lon']);
158 }
And lines 177-188:
177 if (isset($items[$delta]['geom']['top'])) {
178 $bounds_value['top'] = $items[$delta]['geom']['top']; // TODO Use floatval?
179 }
180 if (isset($items[$delta]['right'])) {
181 $bounds_value['right'] = $items[$delta]['geom']['right'];
182 }
183 if (isset($items[$delta]['geom']['bottom'])) {
184 $bounds_value['bottom'] = $items[$delta]['geom']['bottom'];
185 }
186 if (isset($items[$delta]['geom']['left'])) {
187 $bounds_value['left'] = $items[$delta]['geom']['left'];
188 }
Comments
Comment #1
Brandonian CreditAttribution: Brandonian commentedOffhand, that's definitely not the solution, since 'geom' is a separate column from lat/lon, not an overarching array. Will look into it, though
Comment #2
tito.brasolin CreditAttribution: tito.brasolin commentedMaybe the right way to go is to remove "['geom']" from geofield_field_is_empty, geofield_geometry_from_values and so on? Possibly related: Cannot safely change widget type.
Comment #3
Brandonian CreditAttribution: Brandonian commented@tito.brasolin, this is where I eat crow...
You were correct in the original post. I had forgotten that as a part of our updated widget input, I had implemented it to work with an array with a geom attribute. @phayes and I had recently talked about tweaks to how we interact with fields to simplify this process on a code level even further, and I guess I thought I had already implemented that... :-/
Thanks again for catching this. As a reward for being a better debugger than one of the co-maintainers, I gave you the commit credit, along with any bragging rights that come along with it. :-)
Comment #4
Brandonian CreditAttribution: Brandonian commentedCommit for #3: http://drupalcode.org/project/geofield.git/commit/9902d30
Comment #5
malberts CreditAttribution: malberts commentedExcuse me if I'm missing something obvious, but with the current dev version my LAT/LON default values are not populated.
In geofield.widgets.inc:
When I inspect $items I get:
I don't have the data structure that was "fixed" here.
The field used to be "Geocode from another field" with Geometry type "Point (default)". Now it uses the "Latitude / Longitude" widget.
Comment #6
malberts CreditAttribution: malberts commentedOn second thought, this issue is for the default value. I was actually thinking about the value that was set in the field. When editing, shouldn't the LAT/LON field be populated with the value that was saved? My output above is when I'm on an edit form. When I edit the Default value it does put 'lat' and 'lon' in the 'geom' structure.
Comment #7
Brandonian CreditAttribution: Brandonian commented@malberts, Geofield does some processing on the input that converts it to what's finally saved in the database; it's not a 1 to 1 relationship with the data. Geofield currently accepts data as an array with an 'input_format' key and an 'geom' key. This is described in more detail in #1648976: Make it simpler to programmatically add Geofield data, and should be added to the 2.x documentation.
Comment #8
balagan CreditAttribution: balagan commentedAfter some debugging, I found that the suggested 7.x-2.0-alpha2 version should be updated something like
Until the recommended version does not support the ['geom'] and input_format arrays, please update documentation to indicate that the ['geom'] array and the input_format is only used in the devel version.
Comment #10
p4trizio CreditAttribution: p4trizio commentedI know it's an old post, but you must use geofield_compute_values function, it is enough documented in latest module versions
Comment #11
AaronBaumanSame doc needed for 8.x
I'm setting lat, lon, and geo_type, but it's not saving correctly.
This info should be in README
Comment #13
itamair CreditAttribution: itamair as a volunteer commentedLast commit added detailed documentation on how to save a Geofield programmatically in Drupal 8.
Comment #14
itamair CreditAttribution: itamair as a volunteer commented