Permalink
Browse files

Implement hook_presave() for working around PDO empty string insert e…

…rror.
  • Loading branch information...
1 parent 53476ba commit 5ec41bfb398824e2cc4801ab68f276aabd351425 @yhahn yhahn committed Dec 10, 2010
Showing with 19 additions and 0 deletions.
  1. +19 −0 geofield.module
View
@@ -15,6 +15,25 @@ function geofield_field_info() {
}
/**
+ * Implements hook_field_presave().
+ * PDO throws an error when attempting to insert an empty string into a float
+ * field. Go through all values and convert empty strings to NULL.
+ */
+function geofield_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
+ if ($field['type'] === 'geofield') {
+ foreach ($items as $delta => $item) {
+ if (!empty($item)) {
+ foreach ($item as $k => $v) {
+ if ($v === '') {
+ $items[$delta][$k] = NULL;
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
* Implements of hook_content_is_empty().
*
* TODO: lat lon are optional, so this is broken.

1 comment on commit 5ec41bf

@lxbarth

O wow.

Please sign in to comment.