Skip to content
Snippets Groups Projects
Verified Commit 8fac18c8 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3035732 by Lendude, nod_, Vidushi Mehta, Kristen Pol, jungle, larowlan:...

Issue #3035732 by Lendude, nod_, Vidushi Mehta, Kristen Pol, jungle, larowlan: Views UI tags do not use autocomplete suggestions
parent e8ef1456
No related branches found
No related tags found
8 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards,!16Draft: Resolve #2081585 "History storage",!13Resolve #2903456
......@@ -2,6 +2,7 @@
namespace Drupal\views_ui\Controller;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\Core\Url;
......@@ -188,13 +189,15 @@ public function autocompleteTag(Request $request) {
// Keep track of previously processed tags so they can be skipped.
$tags = [];
foreach ($views as $view) {
$tag = $view->get('tag');
if ($tag && !in_array($tag, $tags)) {
$tags[] = $tag;
if (strpos($tag, $string) === 0) {
$matches[] = ['value' => $tag, 'label' => Html::escape($tag)];
if (count($matches) >= 10) {
break;
$view_tag = $view->get('tag');
foreach (Tags::explode($view_tag) as $tag) {
if ($tag && !in_array($tag, $tags, TRUE)) {
$tags[] = $tag;
if (mb_stripos($tag, $string) !== FALSE) {
$matches[] = ['value' => $tag, 'label' => Html::escape($tag)];
if (count($matches) >= 10) {
break 2;
}
}
}
}
......
......@@ -22,7 +22,7 @@ class TagTest extends ViewsKernelTestBase {
protected static $modules = ['views', 'views_ui', 'user'];
/**
* Tests the views_ui_autocomplete_tag function.
* Tests the ViewsUIController::autocompleteTag() function.
*/
public function testViewsUiAutocompleteTag() {
\Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');
......@@ -68,4 +68,41 @@ public function testViewsUiAutocompleteTag() {
$this->assertCount(0, $matches, "Make sure an invalid tag doesn't return anything.");
}
/**
* Tests that comma delimited tags are treated as individual tags.
*
* @dataProvider providerViewsUiAutocompleteIndividualTags
*/
public function testViewsUiAutocompleteIndividualTags($expected_tag, $search_string) {
$controller = ViewsUIController::create($this->container);
$request = $this->container->get('request_stack')->getCurrentRequest();
$tag = 'comma, 你好, Foo bar';
View::create(['tag' => $tag, 'id' => $this->randomMachineName()])->save();
$request->query->set('q', $search_string);
$result = $controller->autocompleteTag($request);
$matches = (array) json_decode($result->getContent());
$this->assertCount(1, $matches);
$this->assertSame($expected_tag, $matches[0]->value);
}
/**
* Data provider for testViewsUiAutocompleteIndividualTags().
*
* @return array[]
* The data set.
*/
public function providerViewsUiAutocompleteIndividualTags() {
return [
'tag' => ['comma', 'comma'],
'case insensitive tag' => ['comma', 'COMMA'],
'Hello in Chinese (partial 1)' => ['你好', '你'],
'Hello in Chinese (partial 2)' => ['你好', '好'],
'Hello in Chinese' => ['你好', '你好'],
'Starts with partial and case-sensitive' => ['Foo bar', 'Foo'],
'Starts with partial and case-insensitive' => ['Foo bar', 'fOO'],
'Ends with partial and case-sensitive' => ['Foo bar', 'bar'],
'Ends with partial and case-insensitive' => ['Foo bar', 'BAR'],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment