Commit 36df8e87 authored by Dries's avatar Dries

Issue #2024111 by damiankloip: Fixed TaxonomyIndexTid filter handler autocomplete does not work.

parent 0a0942a0
......@@ -11,6 +11,7 @@
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 @@ protected function valueValidate($form, &$form_state) {
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 @@ public function validateExposed(&$form, &$form_state) {
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) {
......
......@@ -12,6 +12,9 @@
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);
}
}
......
<?php
/**
* @file
* Contains \Drupal\views\Tests\ViewsTaxonomyAutocompleteTest.
*/
namespace Drupal\views\Tests;
use Drupal\taxonomy\Tests\Views\TaxonomyTestBase;
use Drupal\Component\Utility\MapArray;
/**
* Tests the views taxonomy complete menu callback.
*
* @see views_ajax_autocomplete_taxonomy()
*/
class ViewsTaxonomyAutocompleteTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views');
public static function getInfo() {
return array(
'name' => '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))));
}
}
......@@ -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'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment