diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js index 7dc2c39..7a9e0e0 100644 --- a/core/misc/autocomplete.js +++ b/core/misc/autocomplete.js @@ -71,6 +71,12 @@ function searchHandler (event) { * @param {Function} response */ function sourceData (request, response) { + var elementId = this.element.attr('id'); + + if (!(elementId in autocomplete.cache)) { + autocomplete.cache[elementId] = {}; + } + /** * Filter through the suggestions removing all terms already tagged and * display the available terms to the user. @@ -94,25 +100,18 @@ function sourceData (request, response) { * @param {Object} data */ function sourceCallbackHandler (data) { - // Drupal returns an object, we need an array. - var terms = []; - for (var i in data) { - if (data.hasOwnProperty(i)) { - terms.push(data[i]); - } - } - autocomplete.cache[term] = terms; + autocomplete.cache[elementId][term] = data; // Send the new string array of terms to the jQuery UI list. - showSuggestions(terms); + showSuggestions(data); } // Get the desired term and construct the autocomplete URL for it. var term = autocomplete.extractLastTerm(request.term); // Check if the term is already cached. - if (autocomplete.cache.hasOwnProperty(term)) { - showSuggestions(autocomplete.cache[term]); + if (autocomplete.cache[elementId].hasOwnProperty(term)) { + showSuggestions(autocomplete.cache[elementId][term]); } else { var options = $.extend({ success: sourceCallbackHandler, data: { q: term } }, autocomplete.ajax); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php index 8fa080c..ac84c9e 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php @@ -100,7 +100,7 @@ public function getMatches($field, $instance, $entity_type, $entity_id = '', $pr if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) { $key = '"' . str_replace('"', '""', $key) . '"'; } - $matches[$prefix . $key] = $label; + $matches[] = array('value' => $prefix . $key, 'label' => $label); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php index 616091e..1c12516 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php @@ -200,7 +200,7 @@ protected function getMatchingTerms($tags_typed, array $vids, $tag_last) { if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) { $name = '"' . str_replace('"', '""', $name) . '"'; } - $matches[$prefix . $name] = String::checkPlain($term->label()); + $matches[] = array('value' => $prefix . $name, 'label' => String::checkPlain($term->label())); } return $matches; } diff --git a/core/modules/user/lib/Drupal/user/UserAutocomplete.php b/core/modules/user/lib/Drupal/user/UserAutocomplete.php index 4d36923..a7a20b2 100644 --- a/core/modules/user/lib/Drupal/user/UserAutocomplete.php +++ b/core/modules/user/lib/Drupal/user/UserAutocomplete.php @@ -7,6 +7,7 @@ namespace Drupal\user; +use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Database\Connection; @@ -62,12 +63,12 @@ public function getMatches($string, $include_anonymous = FALSE) { $anonymous_name = $this->configFactory->get('user.settings')->get('anonymous'); // Allow autocompletion for the anonymous user. if (stripos($anonymous_name, $string) !== FALSE) { - $matches[$anonymous_name] = check_plain($anonymous_name); + $matches[] = array('value' => $anonymous_name, 'label' => String::checkPlain($anonymous_name)); } } $result = $this->connection->select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute(); foreach ($result as $account) { - $matches[$account->name] = check_plain($account->name); + $matches[] = array('value' => $account->name, 'label' => String::checkPlain($account->name)); } }