Came across an issue when importing data using migrate where the geofield_field_presave fails at line 292 because a NULL is passed into the foreach.
I am not importing geography but addresses and want the geocoding to be done on save.
The geofield_field_presave gets passed a NULL &$items which causes the problem.
To solve this I updated line 279 to check for NULL (isset($items)) as well as the current check for empty items.
--- a/sites/all/modules/contrib/geofield/geofield.module
+++ b/sites/all/modules/contrib/geofield/geofield.module
@@ -274,7 +274,7 @@ function geofield_field_presave($entity_type, $entity, $field, $instance, $langc
* Geofield Issue: http://drupal.org/node/1886852
* Core Issue: http://drupal.org/node/1253820
*/
- if ($instance['required'] == 0 && empty($items)) {
+ if (($instance['required'] == 0 && empty($items)) || !isset($items)) {
$entity_ids = entity_extract_ids($entity_type, $entity);
if (empty($entity_ids[0])) {
$items = $instance['default_value'];
This solves my problem for the migration and I have reverted the 'patch' after completing the migration.
I am mentioning it here really for others who may have this issue.
The problem stems from _field_invoke() in field.attach.inc which doesn't seem to create the $items array for the hook. So not sure if the issue is further up the stack or if geofield should check.
Data migrated this way still gets geocoded correctly and without the patch normally entered data gets geocoded OK.
Comments
Comment #1
Countzero commentedStumbling on the same issue, but the error still shows up after applying your modification.
I don't import any address for now, do you think empty address fields can cause this issue ?
Dumping the $items array returns NULL, and given the comments in geofield's code, default_value has to be set.
Comment #2
Countzero commentedDid some testing : deleting the geofield field from the CT makes the import work OK, including the address stuff which I was not sure about.
So, your post might the life saver I thought it was when I first read it, but it seems for my case it needs a little more thought.
If you'd have any clue, I'd be most grateful.
EDIT : Something was wrong with my geofield. Deleting and radding it solved the problem. Thanks for you input, it lead on the right track.