I'm creating a new view on a barebone Drupal 8 install. I'm trying to filter this view by a new taxonomy tag and receive an error "There are no entities matching %tag%". Expected behavior is (as it is with 7) that view would be saved with new tag and this tag would be further available for autocomplete.

Comments

gease created an issue. See original summary.

gease’s picture

Issue summary: View changes
lendude’s picture

Trying to reproduce this. The only place I see where I can add a tag to the View is after creation and then choosing 'Edit view name/description' and then adding a tag.

I don't see the error the @gease reported but I do get a javascript error when entering text in the tag field:

TypeError: undefined is not a function (evaluating 'suggestions.indexOf(tagged[i])')

lendude’s picture

Status: Active » Needs review
Issue tags: +Needs manual testing, +JavaScript
StatusFileSize
new639 bytes

Found the reason for the javascript error I got. Don't know if it solves the original reported error, since I still can't reproduce that.

Ajax bug, so needs manual testing (right?).

Problem was that autocomplete expects a numeric array and views_ui returned an associative array. It would seem that autocomplete.js has a function for dealing with this, well according to the doc block, anyway, because the function doesn't appear to do what it says in the doc block...

/**
     * Transforms the data object into an array and update autocomplete results.
     *
     * @param {object} data
     */
    function sourceCallbackHandler(data) {
      autocomplete.cache[elementId][term] = data;

      // Send the new string array of terms to the jQuery UI list.
      showSuggestions(data);
    }

But sending a numeric array fixes it.

dawehner’s picture

Issue tags: +Needs tests

.

lendude’s picture

Added a test that tests if a numeric array is returned.

dawehner’s picture

+++ b/core/modules/views_ui/src/Controller/ViewsUIController.php
@@ -192,7 +192,7 @@ public function autocompleteTag(Request $request) {
+        if (!in_array($tag, $matches)) $matches[] = $tag;

This is not the code style we use

The last submitted patch, 6: views_tag_autocomplete-2574743-6-SHOULD_FAIL.patch, failed testing.

lendude’s picture

StatusFileSize
new1.47 KB

Fixed code style.

The last submitted patch, 4: views_tag_autocomplete-2574743-4.patch, failed testing.

The last submitted patch, 6: views_tag_autocomplete-2574743-6-SHOULD_FAIL.patch, failed testing.

dawehner’s picture

+++ b/core/modules/views_ui/src/Controller/ViewsUIController.php
@@ -192,7 +192,9 @@ public function autocompleteTag(Request $request) {
       $tag = $view->get('tag');
       if ($tag && strpos($tag, $string) === 0) {
-        $matches[$tag] = $tag;
+        if (!in_array($tag, $matches)) {
+          $matches[] = $tag;
+        }
         if (count($matches) >= 10) {
           break;
         }

I'm a bit confused about that. Don't we wether need to adapt it to look something like

        $matches[] = array('value' => $category, 'label' => Html::escape($category));

, see \Drupal\block\Controller\CategoryAutocompleteController::autocomplete

lendude’s picture

Issue tags: -Needs tests
StatusFileSize
new3.59 KB
new3.35 KB

Well, it worked with just a string, but yeah that format looks much better. Thanks for pointing me in the right direction.

Updated the fix like suggested in #12 and updated the tests to match.

lendude’s picture

timisoreana’s picture

Issue tags: -Needs manual testing
StatusFileSize
new35.85 KB

New tag can't be added on Add new view page
a) On Add new view page (/structure/views/add) fill "View name" and "Tagged with" fields
b) Save it
Actual result: There are no entities matching %tag%.
Expected result: New view with entered tag is saved.

lendude’s picture

Title: Cannot create a new view tag » Cannot add a new taxonomy tag with "Tagged with" when creating a new View
Issue summary: View changes
Issue tags: -JavaScript

@timisoreana Ah thank you! Now I get what the original issue is about. It has nothing to do with tagging the View! Updated the issue title and summary to better reflect what this is about and moved my fix to a new issue #2618034: Adding tag to a View gives an error

dawehner’s picture

Status: Needs review » Needs work

So need a new patch here ...

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Status: Needs work » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative

@gease, Thanks for reporting this issue. We rely on issue reports like this one to resolve bugs and improve Drupal core.

I tested this on 9.2.x and was not able to reproduce this error. I followed the steps given in the Issue Summary and #16. I used devel to generate content with tags. I was able to create a view, using the autocomplete field to select the tag. The update preview in the view correctly listed several node. I was also able to enter multiple tags when creating the view. There were no errors displayed or in the log.

Therefore, closing as cannot reproduce. If you are experiencing this problem reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

Thanks!

quietone’s picture

Version: 8.9.x-dev » 9.2.x-dev

Should be 9.2.x