From 800736d367f8f06ac7d55ee583ebf44891a980ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Agnar=20=C3=98deg=C3=A5rd?= <agnar@norweb.no>
Date: Thu, 26 Mar 2015 12:03:02 +0000
Subject: [PATCH] Issue #1411304 by odegard: entity_id in autocomplete hack.

---
 entityreference.module | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/entityreference.module b/entityreference.module
index bdcb562..d337719 100644
--- a/entityreference.module
+++ b/entityreference.module
@@ -1054,13 +1054,13 @@ function entityreference_autocomplete_callback_get_matches($type, $field, $insta
     // Loop through the products and convert them into autocomplete output.
     foreach ($entity_labels as $values) {
       foreach ($values as $entity_id => $label) {
-        $key = "$label ($entity_id)";
         // Strip things like starting/trailing white spaces, line breaks and tags.
-        $key = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($key)))));
+        $label = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($label)))));
         // Names containing commas or quotes must be wrapped in quotes.
-        if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
-          $key = '"' . str_replace('"', '""', $key) . '"';
+        if (strpos($label, ',') !== FALSE || strpos($label, '"') !== FALSE) {
+          $label = '"' . str_replace('"', '""', $label) . '"';
         }
+        $key = str_pad($label, 110) . '(' . $entity_id . ')';
         $matches[$prefix . $key] = '<div class="reference-autocomplete">' . $label . '</div>';
       }
     }
-- 
1.9.1

