From 03927e9614a1b75be04cb4e491a5721f85576bdd Mon Sep 17 00:00:00 2001
From: Dylan Donkersgoed <ddonkersgoed@echidna.ca>
Date: Thu, 23 Jun 2016 09:34:48 -0400
Subject: [PATCH] 2540642-6

---
 .../getlocations_fields/getlocations_fields.module | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/modules/getlocations_fields/getlocations_fields.module b/modules/getlocations_fields/getlocations_fields.module
index 945c2e7..109d603 100644
--- a/modules/getlocations_fields/getlocations_fields.module
+++ b/modules/getlocations_fields/getlocations_fields.module
@@ -209,6 +209,10 @@ function getlocations_fields_field_validate($entity_type, $entity, $field, $inst
  */
 function getlocations_fields_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
 
+  if (getlocations_test_workbench_dupe($entity_type, $entity, $field)) {
+    return;
+  }
+
   $settings = FALSE;
   if (isset($field['settings'])) {
     $settings = $field['settings'];
@@ -274,6 +278,10 @@ function getlocations_fields_field_insert($entity_type, $entity, $field, $instan
  *   $entity->{$field['field_name']}[$langcode], or an empty array if unset.
  */
 function getlocations_fields_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
+  if (getlocations_test_workbench_dupe($entity_type, $entity, $field)) {
+    return;
+  }
+
   $settings = FALSE;
   if (isset($field['settings'])) {
     $settings = $field['settings'];
@@ -4971,3 +4979,33 @@ function template_preprocess_getlocations_fields_distance(&$variables) {
   $variables['longunit'] = getlocations_get_unit_names($units, 'plurals');
   $variables['distance'] = (float)$variables['distance'];
 }
+
+/**
+ * Test whether $field has already been updated for $entity.
+ *
+ * @param string $entity_type
+ *   The entity type of the entity that is being updated.
+ * @param object $entity
+ *   The entity that is being updated.
+ * @param object $field
+ *   The field that is being updated.
+ *
+ * @return bool
+ *   Whether this is a duplicate insert/update.
+ */
+function getlocations_test_workbench_dupe($entity_type, $entity, $field) {
+  if (module_exists('workbench_moderation')
+    && $entity_type === 'node') {
+    $entity_key = reset($entity);
+    $wb_key = "{$entity_type}_{$entity_key}_{$field['id']}";
+    $wb_already_updated = &drupal_static('getlocations_workbench_already_updated',
+      array());
+    if (in_array($wb_key, $wb_already_updated)) {
+      return TRUE;
+    }
+    else {
+      $wb_already_updated[] = $wb_key;
+    }
+  }
+  return FALSE;
+}
-- 
2.8.3

