From f55db455ecd3dac94570263522fb8dc832200bf0 Mon Sep 17 00:00:00 2001
From: Trevor Simonton <trevor@westernascent.com>
Date: Wed, 14 Nov 2012 12:17:13 -0700
Subject: [PATCH] Issue #1835852 by tmsimont: Added incremental unique ID function to assist in unique DOM id generation for IEF elements.

---
 inline_entity_form.module |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/inline_entity_form.module b/inline_entity_form.module
index 9723604..c1a7a98 100644
--- a/inline_entity_form.module
+++ b/inline_entity_form.module
@@ -316,7 +316,7 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins
   $parents = array_merge($element['#field_parents'], array($element['#field_name'], $element['#language']));
 
   // Assign a unique identifier to each IEF widget.
-  $ief_id = $instance['id'];
+  $ief_id = _inline_entity_form_get_new_id();
   // Determine the wrapper ID for the entire element.
   $wrapper = 'inline-entity-form-' . $ief_id;
   $element = array(
@@ -769,6 +769,23 @@ function inline_entity_form_process_entity_form(&$entity_form, &$form_state) {
 }
 
 /**
+ * Generates a new DOM id for an IEF field that is unique to the page.
+ *
+ * @return
+ *   The DOM id that should be used as the form element ID.
+ */
+function _inline_entity_form_get_new_id() {
+  static $ief_domid;
+  if (! isset($ief_domid) || empty($ief_domid)) {
+    $ief_domid = 0;
+  }
+  $ief_domid++;
+  // Generate unique Map ID.
+  $ief_domid = 'ief_element_' . $ief_domid;
+  return $ief_domid;
+}
+
+/**
  * Provides the form for adding existing entities through an autocomplete field.
  *
  * @param $entity_form
@@ -1093,7 +1110,7 @@ function inline_entity_form_field_attach_submit($parent_entity_type, $parent_ent
     if (isset($instance['widget']) && $instance['widget']['type'] == 'inline_entity_form') {
       $field_name = $instance['field_name'];
       $langcode = $form[$field_name]['#language'];
-      $ief_id = $instance['id'];
+      $ief_id = $form[$field_name][$langcode]['#ief_id'];
       // There's no IEF data for this field, skip it.
       if (empty($form_state['inline_entity_form'][$ief_id])) {
         continue;
-- 
1.7.4.msysgit.0

