Problem/Motivation

Steps to reproduce

  • Enable the module
  • Add a geofield field to a node entity
  • Create an instance of the entity
  • Preview the entity.

Expected results
The geofield renders.

Actual results
The website encountered an unexpected error (all in sites/all/libraries/geoPHP/geoPHP.inc):

  • Warning: fwrite() expects parameter 2 to be string, array given in geoPHP::detectFormat() (line 213 of geoPHP.inc).
  • Notice: Undefined index: in geoPHP::load() (line 62 of geoPHP.inc).
  • Exception: geoPHP could not find an adapter of type in geoPHP::load() (line 65 of geoPHP.inc).

This occurs because the node preview workflow (if not that of other entities) calls hook_field_load() and passes the geofield array used in the node edit state. Unfortunately, geofield_field_load() expects an array in WKB format but is not given such.

Proposed resolution

Implement hook_field_attach_submit() and convert the value to the WKB format expected by the subsequent call to the load routine.

This hook is called on entity preview and save. In each case the geometry value (at some point) needs to be set in the WKB format before subsequent processing; either for writing to the backend (on presave) or loading the entity (on preview). Setting the WKB format in hook_field_presave() does not cover the preview workflow. For a node entity, see node_form_build_preview().

This hook implementation should eliminate the need for the same code in geofield_field_presave().

The parameters to this function lead one to ask why the field API does not invoke this hook on a field level (as opposed to the entity) so that the implementing module does not have to inspect the fields on the bundle to see if one of its own is present.

Remaining tasks

Review and test (does a test need to be written?).

User interface changes

None.

API changes

None.

Comments

solotandem’s picture

Status: Active » Needs review
StatusFileSize
new3.39 KB

Attached patch implements proposed resolution.

sylvainm’s picture

I fixed that in IEF with another approach, does this patch fix your problem too?
https://www.drupal.org/node/2558531#comment-10873434