From 5c3f20051cf3852b05081838a934957da438c57e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Agnar=20=C3=98deg=C3=A5rd?= <agnar@norweb.no>
Date: Thu, 17 Sep 2015 13:29:51 +0000
Subject: [PATCH] Issue #1683964 by username: Fix for missing target_id.

---
 entityreference.module | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/entityreference.module b/entityreference.module
index a9893ab..ac3da9e 100644
--- a/entityreference.module
+++ b/entityreference.module
@@ -820,7 +820,9 @@ function entityreference_field_widget_form(&$form, &$form_state, $field, $instan
 
     // Build an array of entities ID.
     foreach ($items as $item) {
-      $entity_ids[] = $item['target_id'];
+      if (isset($item['target_id'])) {
+        $entity_ids[] = $item['target_id'];
+      }
     }
 
     // Load those entities and loop through them to extract their labels.
-- 
1.9.1

