diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
index 0d5dfd4..4579934 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
@@ -54,10 +54,12 @@ public function formElement(array $items, $delta, array $element, $langcode, arr
     foreach ($items as $item) {
       $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
     }
+
+    $vocabulary_name = $field['settings']['allowed_values'][0]['vocabulary'];
     $element += array(
       '#type' => 'textfield',
       '#default_value' => taxonomy_implode_tags($tags),
-      '#autocomplete_path' => $this->getSetting('autocomplete_path') . '/' . $field['field_name'],
+      '#autocomplete_path' => $this->getSetting('autocomplete_path') . '/' . $vocabulary_name,
       '#size' => $this->getSetting('size'),
       '#placeholder' => $this->getSetting('placeholder'),
       '#maxlength' => 1024,
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
index 93cc8d4..4f959ee 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
@@ -214,13 +214,13 @@ function testNodeTermCreationAndDeletion() {
     // Test autocomplete on term 3, which contains a comma.
     // The term will be quoted, and the " will be encoded in unicode (\u0022).
     $input = substr($term_objects['term3']->name, 0, 3);
-    $json = $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input)));
+    $json = $this->drupalGet('taxonomy/autocomplete/' . $this->vocabulary->id(), array('query' => array('q' => $input)));
     $this->assertEqual($json, '{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name)));
 
     // Test autocomplete on term 4 - it is alphanumeric only, so no extra
     // quoting.
     $input = substr($term_objects['term4']->name, 0, 3);
-    $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input)));
+    $this->drupalGet('taxonomy/autocomplete/' . $this->vocabulary->id(), array('query' => array('q' => $input)));
     $this->assertRaw('{"' . $term_objects['term4']->name . '":"' . $term_objects['term4']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->name)));
 
     // Test taxonomy autocomplete with a nonexistent field.
diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc
index fbd29f1..43ec063 100644
--- a/core/modules/taxonomy/taxonomy.pages.inc
+++ b/core/modules/taxonomy/taxonomy.pages.inc
@@ -97,37 +97,43 @@ function taxonomy_term_feed(Term $term) {
  *   };
  * @endcode
  *
- * @param $field_name
- *   The name of the term reference field.
+ * @param string $vocabulary_id
+ *  The ID of the vocabulary.
+ *
+ * @return \Symfony\Component\HttpFoundation\JsonResponse
+ *   Returns the JSON response object containing the autocomplete results.
  *
  * @see taxonomy_menu()
  * @see taxonomy_field_widget_info()
  */
-function taxonomy_autocomplete($field_name) {
+function taxonomy_autocomplete($vocabulary_id) {
   // A comma-separated list of term names entered in the autocomplete form
   // element. Only the last term is used for autocompletion.
   $tags_typed = drupal_container()->get('request')->query->get('q');
 
-  // Make sure the field exists and is a taxonomy field.
-  if (!($field = field_info_field($field_name)) || $field['type'] !== 'taxonomy_term_reference') {
-    // Error string. The JavaScript handler will realize this is not JSON and
-    // will display it as debugging information.
-    print t('Taxonomy field @field_name not found.', array('@field_name' => $field_name));
-    exit;
-  }
-
   // The user enters a comma-separated list of tags. We only autocomplete the last tag.
   $tags_typed = drupal_explode_tags($tags_typed);
-  $tag_last = drupal_strtolower(array_pop($tags_typed));
 
-  $matches = array();
-  if ($tag_last != '') {
+  $term_matches = taxonomy_autocomplete_get_suggestions($vocabulary_id, $tags_typed);
 
-    // Part of the criteria for the query come from the field's own settings.
-    $vids = array();
-    foreach ($field['settings']['allowed_values'] as $tree) {
-      $vids[] = $tree['vocabulary'];
-    }
+  return new JsonResponse($term_matches);
+}
+
+/**
+ * Generates taxonomy autocomplete suggestions.
+ *
+ * @param string $vocabulary_id
+ *   The machine name of the vocabulary to autocomplete on.
+ * @param string $tags_typed
+ *   A comma-separated list of tags. Only the last tag is autocompleted.
+ * @return array
+ *   An associative array of possible suggestions, keyed by the corresponding
+ *   autocomplete field value (including other field values).
+ */
+function taxonomy_autocomplete_get_suggestions($vocabulary_id, $tags_typed) {
+  $tag_last = drupal_strtolower(array_pop($tags_typed));
+  $term_suggestions = array();
+  if ($tag_last != '') {
 
     $query = db_select('taxonomy_term_data', 't');
     $query->addTag('translatable');
@@ -140,7 +146,7 @@ function taxonomy_autocomplete($field_name) {
     // Select rows that match by term name.
     $tags_return = $query
       ->fields('t', array('tid', 'name'))
-      ->condition('t.vid', $vids)
+      ->condition('t.vid', $vocabulary_id)
       ->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
       ->range(0, 10)
       ->execute()
@@ -148,16 +154,14 @@ function taxonomy_autocomplete($field_name) {
 
     $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
 
-    $term_matches = array();
-    foreach ($tags_return as $tid => $name) {
+    foreach ($tags_return as $name) {
       $n = $name;
       // Term names containing commas or quotes must be wrapped in quotes.
       if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
         $n = '"' . str_replace('"', '""', $name) . '"';
       }
-      $term_matches[$prefix . $n] = check_plain($name);
+      $term_suggestions[$prefix . $n] = check_plain($name);
     }
   }
-
-  return new JsonResponse($term_matches);
+  return $term_suggestions;
 }
