Two things in openlayers_geofield_widget_element_validate():

  • It's looking for $element[0]['widget']['#value'], which doesn't exist. However, $element[0]['geom']['#value'] (as well as $form_state) has geometry coming in from the OL map.
  • Calls to geofield_element_validate(), which doesn't exist.

Comments

netbek’s picture

Patch attached. Proceed with caution because it needs further testing. Also, I'm not sure if it's entirely correct (doesn't use openlayers_geofield_override_element_delta()), and if the transition from WKT to WKB storage could be handled better.

Tested with:
* fields: multiple value addressfield and taxonomy reference
* multi-value input handling: Match Multiples
* storage: "Each simple feature as a separate field" (single), and as collection

I've also changed geofield_field_presave() because in my setup it's called twice when saving a node. This resulted in NULL values saved to db due to WKB loaded as WKT in geofield_compute_values() because no 'input_format' in second call.

netbek’s picture

Status: Active » Needs review

Marking for review because others are also trying to geocode a point with the OL widget and failing with the latest devs of geofield, geocoder, geophp, openlayers. See #1651200-5: Fatal error: Call to undefined method geoPHP::geosInstalled() onwards. Patch in #1 solves the issue for me, but I'd appreciate if others could try it out.

phayes’s picture

This is generally looking good, but can you explain, in the patch, why you are remove openlayers_geofield_override_element_delta

netbek’s picture

I'm not sure what its purpose is now because I'm not assigning values using geofield_element_validate($element, $form_state). Looking at the repo history http://drupalcode.org/project/geofield.git/blobdiff/22bc5ae452da1784d558... I don't think changes to #parents and #array_parents as done in openlayers_geofield_override_element_delta() was needed in geofield_element_validate(). Maybe it was useful later down the chain when saving or previewing a node in an earlier version of geofield. [edit]

Here's a test with 2 points with the latest dev + patch:

elseif ($container_delta['#widget_settings']['data_storage'] == 'single') {
  $element = $container_delta;
  print_r($element);

  foreach ($geoms as $delta => $geom) {
	openlayers_geofield_override_element_delta($element, 0, $delta);
	print_r($element);

	$form_state['values'][$field_name][LANGUAGE_NONE][$delta] = array(
	  'input_format' => 'wkb',
	  'geom' => $geom->out('wkb')
	);
  }
}

Here's the abbreviated output from print_r() to see what's done in openlayers_geofield_override_element_delta(). Called 3 times - once at the top and once for each of 2 deltas:

    [geom] => Array
        (
            [#parents] => Array
                (
                    [0] => field_geofield
                    [1] => und
                    [2] => 0
                    [3] => geom
                )
            [#array_parents] => Array
                (
                    [0] => field_geofield
                    [1] => und
                    [2] => 0
                    [3] => geom
                )
		)
    [#parents] => Array
        (
            [0] => field_geofield
            [1] => und
            [2] => 0
        )
    [#array_parents] => Array
        (
            [0] => field_geofield
            [1] => und
            [2] => 0
        )
    [geom] => Array
        (
            [#parents] => Array
                (
                    [0] => field_geofield
                    [1] => und
                    [2] => 0
                    [3] => geom
                )
            [#array_parents] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                    [3] => 0
                )
		)
    [#parents] => Array
        (
            [0] => field_geofield
            [1] => und
            [2] => 0
        )
    [#array_parents] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
        )
    [geom] => Array
        (
            [#parents] => Array
                (
                    [0] => field_geofield
                    [1] => und
                    [2] => 1
                    [3] => geom
                )
            [#array_parents] => Array
                (
                    [0] => 1
                    [1] => 1
                    [2] => 1
                    [3] => 1
                )
		)
    [#parents] => Array
        (
            [0] => field_geofield
            [1] => und
            [2] => 1
        )
    [#array_parents] => Array
        (
            [0] => 1
            [1] => 1
            [2] => 1
        )
dpw’s picture

I was getting the error:
Only NDR (little endian) SKB format is supported at the moment in WKB->getGeometry() line (line 48 of geoPHP/lib/adapters/WKB.class.php)

and Patch #1 seems to have resolved this issue. Still testing...

I was using Geofield 1.1 and upgraded to latest 2.x dev when the error started...
using latest OpenLayers dev.

netbek’s picture

Regarding the Exception: Only NDR (little endian) SKB format error and the patch in #1, some results after applying the patch to latest dev geofield, and using latest dev geocoder, geophp:

Success:
#1757374-6: Widget errors with addressfield / geofield / openLayers

Failure:
#1651200-16: Fatal error: Call to undefined method geoPHP::geosInstalled()

phayes’s picture

Assigned: Unassigned » phayes
phayes’s picture

Status: Needs review » Needs work

This particular WKB bug is now fixed, but we're still getting problems with delta and single vs collection handling.

phayes’s picture

Status: Needs work » Fixed

Optimistically marking this as fixed. Please feel free to re-open if you have issues.

netbek’s picture

StatusFileSize
new1.36 KB

Almost there. It now works when saving a node, but not when previewing a node. The infamous Exception: Only NDR (little endian) SKB format error is thrown after hitting the Preview button. _geofield_openlayers_formatter and openlayers_field_widget_form look for a geom index, but there is none.

Here's an abbreviate backtrace from _geofield_openlayers_formatter:

    [3] => Array
        (
            [file] => /sites/all/modules/geofield/geofield.formatters.inc
            [line] => 392
            [function] => load
            [class] => geoPHP
            [type] => ::
            [args] => Array
                (
                    [0] => P
                    [1] => wkb
                )
        )
    [4] => Array
        (
            [file] => /sites/all/modules/geofield/geofield.formatters.inc
            [line] => 336
            [function] => _geofield_openlayers_formatter
            [args] => Array
                (
                    [0] => geofield_formatter_map
                    [1] => Array
                        (
                            [0] => POINT (18.4240553 -33.9248685)
                            [1] => POINT (31.027581 -29.857876)
                        )
                )
        )

Patch attached. I'm not sure if assuming the values are in WKT when geom is absent is necessarily the best approach, but it works for me as a temporary measure -- perhaps until the format of values passed to the various functions is declared or auto-detected.

Tested with:
* storage: single; collection
* multi-value input handling: match multiples; multiple to single

phayes’s picture

Status: Fixed » Needs review

The latest version of geoPHP (including the dev version of the geophp module) now has automatic format detection, so we can omit the second 'wkb' / 'wkt' argument being passed to geoPHP::load() . just geoPHP::load($value) should do the trick

netbek’s picture

StatusFileSize
new1.35 KB

Nice. Patch modified then and tested with the latest dev geophp and geofield.

Edit: I took out the 'wkt'. If you feel the 'wkb' should go to, go ahead.

phayes’s picture

Status: Needs review » Fixed

Committed!

I removed the 'wkb' stuff. I really want to get geoPHP format detection in such a kickass state that we can feel like we can just throw values at it and it will read it correctly.

netbek’s picture

Agreed. I was hesitant to try the latest dev geophp after the last minor git hiccup, so I didn't see it earlier. I was hoping someone would add auto-detect because it solves many potential headaches.

Status: Fixed » Closed (fixed)

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