diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php index d98ac1bcf62..ef6101a73f2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php @@ -11,6 +11,7 @@ use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\Component\Annotation\PluginID; use Drupal\views\Plugin\views\filter\ManyToOne; +use Drupal\Component\Utility\Tags; /** * Filter by term id. @@ -217,7 +218,7 @@ class TaxonomyIndexTid extends ManyToOne { return; } - $values = drupal_explode_tags($form_state['values']['options']['value']); + $values = Tags::explode($form_state['values']['options']['value']); $tids = $this->validate_term_strings($form['value'], $values); if ($tids) { @@ -271,7 +272,7 @@ class TaxonomyIndexTid extends ManyToOne { return; } - $values = drupal_explode_tags($form_state['values'][$identifier]); + $values = Tags::explode($form_state['values'][$identifier]); $tids = $this->validate_term_strings($form[$identifier], $values); if ($tids) { diff --git a/core/modules/views/includes/ajax.inc b/core/modules/views/includes/ajax.inc index 2789d6de07d..d20bfb98a65 100644 --- a/core/modules/views/includes/ajax.inc +++ b/core/modules/views/includes/ajax.inc @@ -12,6 +12,9 @@ use Drupal\Core\Ajax\ReplaceCommand; use Drupal\views\Ajax\ScrollTopCommand; use Drupal\views\Ajax\ViewAjaxResponse; use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Component\Utility\Tags; +use Drupal\Component\Utility\Unicode; +use Drupal\Component\Utility\String; /** * @defgroup views_ajax Views AJAX library @@ -153,13 +156,13 @@ function views_ajax_form_wrapper($form_id, &$form_state) { * @see taxonomy_autocomplete() */ function views_ajax_autocomplete_taxonomy($vid) { - // The user enters a comma-separated list of tags. We only autocomplete the last tag. - $tags_typed = drupal_explode_tags(drupal_container()->get('request')->query->get('q')); - $tag_last = drupal_strtolower(array_pop($tags_typed)); + // The user enters a comma-separated list of tags. We only autocomplete the + // last tag. + $tags_typed = Tags::explode(Drupal::request()->query->get('q')); + $tag_last = Unicode::strtolower(array_pop($tags_typed)); + $term_matches = array(); - $matches = array(); if ($tag_last != '') { - $query = db_select('taxonomy_term_data', 't'); $query->addTag('term_access'); @@ -176,9 +179,8 @@ function views_ajax_autocomplete_taxonomy($vid) { ->execute() ->fetchAllKeyed(); - $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : ''; + $prefix = count($tags_typed) ? Tags::implode($tags_typed) . ', ' : ''; - $term_matches = array(); foreach ($tags_return as $tid => $name) { $n = $name; // Term names containing commas or quotes must be wrapped in quotes. @@ -186,7 +188,7 @@ function views_ajax_autocomplete_taxonomy($vid) { $n = '"' . str_replace('"', '""', $name) . '"'; } // Add term name to list of matches. - $term_matches[$prefix . $n] = check_plain($name); + $term_matches[$prefix . $n] = String::checkPlain($name); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php new file mode 100644 index 00000000000..9ba340fc0ea --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php @@ -0,0 +1,55 @@ + 'View taxonomy autocomplete', + 'description' => 'Tests the view taxonomy autocomplete AJAX callback.', + 'group' => 'Views' + ); + } + + /** + * Tests the views_ajax_autocomplete_taxonomy() AJAX callback. + */ + public function testTaxonomyAutocomplete() { + $this->user = $this->drupalCreateUser(array('access content')); + $this->drupalLogin($this->user); + $base_autocomplete_path = 'admin/views/ajax/autocomplete/taxonomy/' . $this->vocabulary->vid; + + // Test that no terms returns an empty array. + $this->assertIdentical(array(), $this->drupalGetJSON($base_autocomplete_path)); + + // Test a with whole name term. + $label = $this->term1->label(); + $expected = MapArray::copyValuesToKeys((array) $label); + $this->assertIdentical($expected, $this->drupalGetJSON($base_autocomplete_path, array('query' => array('q' => $label)))); + // Test a term by partial name. + $partial = substr($label, 0, 2); + $this->assertIdentical($expected, $this->drupalGetJSON($base_autocomplete_path, array('query' => array('q' => $partial)))); + } + +} diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 279f795edc5..0e5922b69b2 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -308,6 +308,7 @@ function views_menu() { // does not support a vid a argument anymore $items['admin/views/ajax/autocomplete/taxonomy/%'] = array( 'page callback' => 'views_ajax_autocomplete_taxonomy', + 'page arguments' => array(5), 'theme callback' => 'ajax_base_page_theme', 'access callback' => 'user_access', 'access arguments' => array('access content'),