Views for Drupal 7 supported taxonomy vocabulary as a contextual filter for terms, but Drupal 8 doesn't seem to. However, it does support taxonomy vocabulary as a regular filter.

The first attached screenshot is from a Drupal 7 views contextual filter interface, the second is that of Drupal 8, and the third is the regular filter for Drupal 8.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bbinkovitz’s picture

Issue summary: View changes

Updated issue summary.

bbinkovitz’s picture

Issue summary: View changes

Updated issue summary.

bbinkovitz’s picture

Issue summary: View changes

Updated issue summary.

bbinkovitz’s picture

Issue summary: View changes

Updated issue summary.

dawehner’s picture

Category: feature » bug
Issue tags: +VDC

Adding tag. These aren't available anymore, probably due to the conversion of vocabularies to configuration entities, though
these regressions potentially should be marked as a bug.

Thank you for reporting the issue. This is really valuable information given the fact that not many actually use views already in D8.

dawehner’s picture

Issue summary: View changes

Updated issue summary.

Upchuk’s picture

Version: 8.0-alpha2 » 8.0.x-dev
Issue summary: View changes

Is this going to get some attention?

Is the views argument plugin VocabularyVid used for anything then?

stBorchert’s picture

Status: Active » Needs review
FileSize
7.88 KB

The attached patch simply "enables" the vocabulary contextual filter and adds a test.

Lendude’s picture

+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyVocabularyArgumentTest.php
@@ -0,0 +1,82 @@
+
+    // Create some term with markup in the label.
...
+    $this->assertEscaped($this->terms[0]->label());
...
+    $this->assertNoEscaped($this->terms[1]->label());

Why the markup? Without the markup you can just assertText, seems more straight forward to me.

The rest looks good to go.

stBorchert’s picture

The test is basically copied (and slightly adjusted) from TaxonomyDefaultArgumentTest and TaxonomyTermArgumentDepthTest so I simply used, whats already in core :).

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Heh, yeah, doesn't make a lot of sense there either, but good enough reason for me :)

Manually tested this and fixes the issue and adds more test coverage, great!

queenvictoria’s picture

Works for me too. Thanks!

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll, +Novice

Patch needs a re-roll for 8.1.x.

kostyashupenko’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
7.97 KB

Status: Needs review » Needs work

The last submitted patch, 9: taxonomy_vocabulary-2048733-9.patch, failed testing.

Lendude’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Needs review

Putting it on the right branch

Status: Needs review » Needs work

The last submitted patch, 9: taxonomy_vocabulary-2048733-9.patch, failed testing.

Lendude’s picture

The reroll isn't quite right.

  1. +++ b/core/modules/taxonomy/src/TermViewsData.php
    @@ -71,8 +71,8 @@ public function getViewsData() {
    -    $data['taxonomy_term_field_data']['vid']['field']['help'] = t('The vocabulary name.');
    

    This shouldn't be removed.

  2. +++ b/core/modules/taxonomy/src/TermViewsData.php
    @@ -71,8 +71,8 @@ public function getViewsData() {
    +    unset($data['taxonomy_term_field_data']['vid']['field']);
    

    This unset should not be done.

kostyashupenko’s picture

Lendude’s picture

Thanks for the rerolls @kostyashupenko!

+++ b/core/modules/taxonomy/src/TermViewsData.php
@@ -71,8 +71,9 @@ public function getViewsData() {
+

one last nitpick: extra newline isn't needed.

Ankit Agrawal’s picture

Ankit Agrawal’s picture

Lendude’s picture

Went through this again, but still felt it could use a bit of a clean up. So here is the cleaned up version of the patch, and the test-only version.

The last submitted patch, 18: 2048733-18-TEST_ONLY.patch, failed testing.

swati_qa’s picture

The last patch 2048733-18.patch does not apply, it gives error.

swati_qa’s picture

FileSize
35.62 KB

Status: Needs review » Needs work

The last submitted patch, 18: 2048733-18.patch, failed testing.

Lendude’s picture

swati_qa’s picture

FileSize
42.12 KB

The last submitted patch 23: 2048733-23.patch, failed to apply

swati_qa’s picture

Status: Needs review » Reviewed & tested by the community
swati_qa’s picture

Status: Reviewed & tested by the community » Needs work
Lendude’s picture

Status: Needs work » Needs review

@swati_qa You tried to apply it to 8.0.x, not 8.1.x. The patch in #23 is for 8.1.x

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now 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.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.

Status: Needs review » Needs work

The last submitted patch, 23: 2048733-23.patch, failed testing.

The last submitted patch, 23: 2048733-23.patch, failed testing.

Lendude’s picture

merauluka’s picture

I just applied #32 to my 8.1.9 site and it worked perfectly.

Thanks!

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyVocabularyArgumentTest.php
@@ -0,0 +1,81 @@
+  public function testTermWithVocabularyArgument() {
+    $this->drupalGet('test_argument_taxonomy_vocabulary/' . $this->vocabularies[0]->id());
+    // First term should be present.
+    $this->assertText($this->terms[0]->label());
+    // Second term should not be present.
+    $this->assertNoText($this->terms[1]->label());
+  }

This is a really clear test, thank you!

alexpott’s picture

Category: Bug report » Task
Status: Reviewed & tested by the community » Fixed

Committed 1e95bd7 and pushed to 8.3.x. Thanks!

Only added to 8.3.x as nothing is broken per-se - this is just enabling something that was available in Drupal 7 views.

diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyVocabularyArgumentTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyVocabularyArgumentTest.php
index 8e45910..532335f 100644
--- a/core/modules/taxonomy/src/Tests/Views/TaxonomyVocabularyArgumentTest.php
+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyVocabularyArgumentTest.php
@@ -1,10 +1,5 @@
 <?php
 
-/**
- * @file
- * Contains \Drupal\taxonomy\Tests\Views\TaxonomyVocabularyArgumentTest.
- */
-
 namespace Drupal\taxonomy\Tests\Views;
 
 use Drupal\taxonomy\Entity\Vocabulary;

Removed this on commit since it is no longer the coding standard.

  • alexpott committed 1e95bd7 on 8.3.x
    Issue #2048733 by Lendude, kostyashupenko, Ankit Agrawal, stBorchert,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jayemel’s picture

Is this going to make it in to a release? As of 8.8.4 there is no option for a Vocabulary contextual filter.

bserem’s picture

@jmljuniort ss far as I can tell you need to add a term relationship to get the vocabulery contextual filter in a content view.