Problem/Motivation

Given that you have a View configured to use term names as arguments.
Given that the View tries to validate these terms against one vocabulary.
Given that you have two terms, in two different vocabularies, that have the exact same name.
When you try to use this term name as an argument in your View, it is rejected by the \Drupal\taxonomy\Plugin\views\argument_validator\TermName::validateArgument() method even if it should not.

Here is how the TermName::validateArgument() currently works:

load all the terms that matches the argument name

for each term
  if the term does not belong to an allowed vocabulary
    return FALSE

// If ALL the terms belongs to an allowed vocabulary
return TRUE

Note 1: If we are in that case and we force this validator to pass, the argument still uses the good term for the SQL request.
Note 2: that argument validator does not support multiple values

Steps to reproduce

  1. Install Drupal standard
  2. Create a vocabulary "Test" with a term "Yolo"
  3. Create a term "Yolo" in the vocabulary "Tags"
  4. Create an "Article" node using the "Yolo" tag
  5. Create a view of articles
  6. Add a "Taxonomy term referenced from field_tags" relation
  7. Add a "Taxonomy term: Name" argument with a "Taxonomy term name" validation criteria restricted on "Tags" vocabulary
  8. In the preview contextual filters, input "Yolo" then submit

Expected result: your article is shown
Current restult: "No query was run"

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions Done
Reroll the patch if it no longer applies. Instructions Done
Update the issue summary Instructions Done
Add automated tests Instructions
Update the patch to incorporate feedback from reviews (include an interdiff) Instructions Done
Manually test the patch Novice Instructions Done
Add steps to reproduce the issue Novice Instructions Done
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions Done

Proposed resolution

Fix TermName::validateArgument() so it works this way:

load all the terms that matches the argument name

for each term
  if the term belongs to an allowed vocabulary
    return TRUE

// If none of the terms belongs to an allowed vocabulary
return FALSE

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#109 interdiff_107-109.txt4.79 KBdanflanagan8
#109 2494617-109.patch15.29 KBdanflanagan8
#107 interdiff_105-107.txt1.41 KBdanflanagan8
#107 2494617-107.patch11.88 KBdanflanagan8
#105 interdiff_104-105.txt694 bytesdanflanagan8
#105 2494617-105-FAIL.patch10.47 KBdanflanagan8
#104 2494617-104-FAIL.patch10.47 KBdanflanagan8
#99 2494617-99.patch11.29 KBnikitagupta
#97 2494617-97-terms_with_same_name_with_tests.patch11.23 KBjoey-santiago
#75 drupal_views_argument_validator_TermName-2494617-75.patch11.01 KBduaelfr
#73 interdiff.txt699 bytesboobaa
#73 drupal_views_argument_validator_TermName-2494617-73.patch11.12 KBboobaa
#65 interdiff-2494617-57-65.txt699 bytesstborchert
#65 drupal_views_argument_validator_TermName-2494617-65.patch11.22 KBstborchert
#57 drupal-2494617-57.patch11.12 KBlendude
#57 interdiff-2494617-46-57.txt2.3 KBlendude
#46 drupal-2494617-46.patch10.11 KBlendude
#46 interdiff-2494617-43-46.txt1.97 KBlendude
#43 drupal-2494617-43.patch10.06 KBlendude
#43 interdiff-2494617-39-43.txt1.59 KBlendude
#39 interdiff-2494617-37-39.txt3.58 KBlendude
#39 drupal-2494617-39.patch10.14 KBlendude
#39 drupal-2494617-39-TEST_ONLY.patch8.55 KBlendude
#37 drupal-2494617-37.patch10.15 KBshreya shetty
#34 drupal-2494617-34.patch4.13 KBshreya shetty
#28 drupal-2494617-28.patch10.1 KBdrubb
#21 drupal-2494617-21.patch10.05 KBbès
#19 drupal-2494617-19.patch10.31 KBbès
#5 validate_term_name.jpg32.21 KBbès
#4 fix-2494617-3.patch734 bytesbès
#1 fix-2494617.patch713 bytesbès

Comments

bès’s picture

Status: Active » Needs review
StatusFileSize
new713 bytes
bès’s picture

Title: TermName views argument_validator in not working as expected » TermName views argument_validator is not working as expected
dawehner’s picture

Mh, are you sure this is the expected behaviour?

I would assume that you want to validate all entries. Do you remember how the behaviour has been in Drupal 7?

bès’s picture

StatusFileSize
new734 bytes

Oops it's not the good patch, sorry

bès’s picture

StatusFileSize
new32.21 KB

I think the behavior is good. I add a screenshot of the configuration screen for that.
contextual filter admin configuration extract

We want to validate that a taxonomy term passed in the url match a specifc sets of vocabularies.
If we have multiple terms existing we need to check that at least one term match one of the vocabulaires not all of them.

jibran’s picture

Issue tags: +Needs tests

Can we create some tests for the problem described in IS?

dawehner’s picture

If we have multiple terms existing we need to check that at least one term match one of the vocabulaires not all of them.

Honestly, I would expect that all the terms match the configured list of vocabularies ... because this is what you want to filter by at the end ...

bès’s picture

Issue summary: View changes

The multiple terms that I talked about are terms that are not passed as argument but just terms in the databases.

Let's say that I have 2 vocabularies "Tags" and "Country".
In each of theses I have the term "France".

Then I configure the views as this screenshot

If the view receive "France" as its only one arguments, the test will fail because it will test again the "France" from the "Country" vocabulary.

Anyway, thanks @dawehner because you also right that my patch is not good in case we have multiple terms passed as argument. I will work on that.

bès’s picture

After verification the TermName argument validator is not multiple arguments capable. So we don't have to care of that for now.

bès’s picture

I assume that this issue https://www.drupal.org/node/1739846 will help me to add a more specific test case once it will be closed.

dawehner’s picture

That argument is convincing ... yeah that code is just no obvious to read.
I think instead we should not add the todo here but rather make the entire logic easier to read, until we potentially have multiple terms support.

duaelfr’s picture

Issue summary: View changes
Status: Needs review » Needs work

We have multiple term support. The validator is called once per value in the argument.

(I just updated the IS with a bunch of information)

duaelfr’s picture

duaelfr’s picture

Issue summary: View changes

Fixed pseudo code indentation.

bès’s picture

We have multiple term support.

No TermName argument_validator does not currently support multiple term (via , or + signs)

duaelfr’s picture

Issue summary: View changes

Fixed the IS, sorry for that misunderstanding.

bès’s picture

Cross post with @DuaelFr during IS edition :)

Please let the multiple term stuff out of the range of this issue since it leads to misunderstanding. If we need this feature we can open a new issue for that.

In our case and to be clear about the code, the $terms in the patch is an array of all the terms in the database, that match the argument name.

duaelfr’s picture

Issue tags: +HappyDays1506

We are going to finalize this patch this afternoon.

bès’s picture

Status: Needs work » Needs review
StatusFileSize
new10.31 KB

Here is a patch with a new version that only load the terms from bundles that has to be validated. Also contains tests.

dawehner’s picture

This certainly is an improvement, fixes a bug and adds test coverage, even I still think that using the foreach which technically isn't is really confusing.

+++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
@@ -71,22 +71,23 @@ public function validateArgument($argument) {
-}
+}
\ No newline at end of file

Do you mind adding a newline? I guess someone can do that on commit as well.

bès’s picture

StatusFileSize
new10.05 KB

Here is a new version with the newline.

About the foreach, I remember our irc chat about the possibility of removing it. But, we found that we need to test each term via validateEntity() because it also check access.

Status: Needs review » Needs work

The last submitted patch, 21: drupal-2494617-21.patch, failed testing.

bès’s picture

Status: Needs work » Needs review

reroll test

Bès queued 21: drupal-2494617-21.patch for re-testing.

DuaelFr queued 21: drupal-2494617-21.patch for re-testing.

duaelfr’s picture

Status: Needs review » Reviewed & tested by the community

Testbot is still happy and the newline is there.
So, let's RTBC and get this bug fixed!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
+++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
@@ -71,22 +71,24 @@ public function validateArgument($argument) {
-    $terms = $this->termStorage->loadByProperties(array('name' => $argument));
...
+    $bundles = $this->options['bundles'];
+    if (count($bundles)) {

So if $bundles is empty this will fatal because $terms is not defined. We're obviously missing test coverage.

drubb’s picture

StatusFileSize
new10.1 KB

Modified patch #21 for empty bundles.

drubb’s picture

Status: Needs work » Needs review
duaelfr’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice, -Needs tests

That looks good to me.
Thank you @drubb

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: drupal-2494617-28.patch, failed testing.

Status: Needs work » Needs review

Bès queued 28: drupal-2494617-28.patch for re-testing.

lendude’s picture

Status: Needs review » Needs work

Looks great, just a bit of nitpicking:

  1. +++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
    @@ -71,22 +71,26 @@ public function validateArgument($argument) {
    +    // If restricted by bundle.
    

    Can we make this a proper english sentence that actually describes what's happening?

  2. +++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
    @@ -71,22 +71,26 @@ public function validateArgument($argument) {
    +    if (empty($terms)) {
    

    maybe change this to !empty and move the foreach into this, bit more concise.

shreya shetty’s picture

StatusFileSize
new4.13 KB

to make it more concise added !empty condition

shreya shetty’s picture

Status: Needs work » Needs review
duaelfr’s picture

Status: Needs review » Needs work

@Shreya Shetty thank you for your work but I think that there is something wrong in the patch you posted.
Previous patch file was 10.1KB, yours is 4.13KB and contains a lot of unwanted changes (mostly on coding standards but not only).

You should restart from #28 and just change what's asked in #33. If you do that, please also post an interdiff file.

If needed, you can find a good documentation of what to do on these pages :
- https://www.drupal.org/contributor-tasks/create-patch
- https://www.drupal.org/novice

shreya shetty’s picture

StatusFileSize
new10.15 KB
shreya shetty’s picture

Status: Needs work » Needs review
lendude’s picture

Issue tags: -views arguments +VDC
StatusFileSize
new8.55 KB
new10.14 KB
new3.58 KB

I think this is almost ready, but needed a bit of a clean up I feel. Fixed some comments, added some comments, took out the mockStandardInstall bit and just moved it to setup.

Also added a test only patch cause we didn't have one of those yet.

The last submitted patch, 39: drupal-2494617-39-TEST_ONLY.patch, failed testing.

duaelfr’s picture

Status: Needs review » Reviewed & tested by the community

Excellent! Thank you @Lendude!
I made a round of manual testing and the bug is still fixed by the last patch.
Nothing to add about the code neither.
Let's get it commited! :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
    @@ -69,22 +69,26 @@ public function validateArgument($argument) {
    -    // Not knowing which term will be used if more than one is returned check
    -    // each one.
    -    foreach ($terms as $term) {
    -      if (!$this->validateEntity($term)) {
    -        return FALSE;
    -      }
    ...
    +      foreach ($terms as $term) {
    +       if ($this->validateEntity($term)) {
    +         // We only need one of the terms to be valid, so return TRUE when we
    +         // find one.
    +         return TRUE;
    +       }
    

    Not the same logic... why has this changed? And is this change correct?

  2. +++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
    @@ -69,22 +69,26 @@ public function validateArgument($argument) {
    +    if (!empty($terms)) {
    

    loadByProperties always returns an array so checking if empty is not needed.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB
new10.06 KB

1. Yeah that's the whole point of this fix, instead of returning FALSE when one term doesn't pass, return TRUE when one term does pass and only return FALSE when all terms don't pass.

2. Good point, fixed.

also put the use statements in the right order.

duaelfr’s picture

Status: Needs review » Reviewed & tested by the community

Still working :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
FILE: ...odules/taxonomy/src/Plugin/views/argument_validator/TermName.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
 84 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found
    |       |     9
 85 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found
    |       |     9
 86 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found
    |       |     9
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...dules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
 18 | ERROR | [x] Separate the @group and @see sections by a blank
    |       |     line.
 55 | ERROR | [ ] If the line declaring an array spans longer than 80
    |       |     characters, each element should be broken into its
    |       |     own line
 64 | ERROR | [x] Missing function doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 82ms; Memory: 5.75Mb

Some minor code style things to fix up.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new1.97 KB
new10.11 KB

fixed code style per #45

duaelfr’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @alexpott and @Lendude

$ git ac https://www.drupal.org/files/issues/drupal-2494617-46_0.patch

$ git st
On branch 8.0.x
Your branch is up-to-date with 'origin/8.0.x'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
	new file:   core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php
	new file:   core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_term_name_argument_test.yml

$ phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md `git diff --name-only --cached`

$ phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md `git diff --name-only --cached`

All clear!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
@@ -69,22 +69,24 @@ public function validateArgument($argument) {
-    // Not knowing which term will be used if more than one is returned check
-    // each one.
+    // $terms are already bundle tested but we need to test access control.
     foreach ($terms as $term) {
-      if (!$this->validateEntity($term)) {
-        return FALSE;
+      if ($this->validateEntity($term)) {
+        // We only need one of the terms to be valid, so return TRUE when we
+        // find one.
+        return TRUE;
       }
     }
-
-    return TRUE;
+    return FALSE;

Looking at other argument validators (eg. \Drupal\user\Plugin\views\argument_validator\UserName) I think we should revert this and check emptiness of $terms above. This means that if we ever make the TermName multiple capable then this logic will still work correctly. Also (and more importantly) if the result is not limited by bundle and there a two terms with the same name in different bundles - one which the user has access to and one which they don't - the current behaviour in HEAD is to return FALSE. With the current patch it would return TRUE. I don't think this behaviour change is desired.

duaelfr’s picture

@alexpott let's split your comment in two parts.

1- regarding the multiple capacity.
This validator does not need to be multiple capable as Views sends it the values one by one. It might allow to optimize a bit but I'm not even sure it's possible. The change you ask for is quite simple so we could do it, though.

2- regarding the access control.
The purpose of this validator is to validate that the given term name belong to a term in the wanted vocabularies and of which the user has access. Somewhere else or somehow else, Views uses the proper term for its request.
Currently, if two terms have the same name, one you can access and the other you cannot, this validator is going to deny you the access to the View. I don't think it's the behavior we want.

alexpott’s picture

Currently, if two terms have the same name, one you can access and the other you cannot, this validator is going to deny you the access to the View. I don't think it's the behavior we want.

Well at the very least we need to add a test around this behaviour BUT also this is different what happens with Term for example where if you can't access any of the terms it will prevent access. I'm not convinced the behaviour change is desired - if you have per bundle access on Terms you need to limit views using this argument to a specific bundle (imo).

bès’s picture

Issue summary: View changes

if the result is not limited by bundle and there a two terms with the same name in different bundles - one which the user has access to and one which they don't - the current behaviour in HEAD is to return FALSE. With the current patch it would return TRUE. I don't think this behaviour change is desired.

This behaviour has been changed between D7 and D8. I tested that on a D7 installation with TAC

Given two taxonomies : Tags and taxo both with the 'test' term.
The taxo 'test' term is deny for auth.
With a view that do not bundle filer.
When access to /path/to/view/test admin user can see the contents and auth only the one in Tags.
http://i.haza.fr/di/9J95/2494617-d7-test.png

bès’s picture

Issue summary: View changes
duaelfr’s picture

duaelfr’s picture

@alexpott about your comparison with the Term validator, I think we cannot really do the same. The thing is that the Term validator take a TID as argument which cannot match more than one term. So it's normal that if the user cannot access this term we deny immediately return FALSE. In our case, the same term name can match a lot of different terms, even in the same vocabulary. Plus, I agree with @Bès about the regression, I made the same tests as him under D7 and it used to work well.

Do we still need to revert something as you said in #48 or is the last patch OK?

alexpott’s picture

@Bès nice work testing this on D7.

So this is tricky because something that was an empty view currently in D8 will now have a response but it appears that this is the way it was in D7. I definitely think we need a test of the behaviour regardless of how we solve it and I would like the views maintainers to have a think about what is best to do...

dawehner’s picture

  1. +++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
    @@ -69,22 +69,24 @@ public function validateArgument($argument) {
         foreach ($terms as $term) {
    -      if (!$this->validateEntity($term)) {
    -        return FALSE;
    +      if ($this->validateEntity($term)) {
    +        // We only need one of the terms to be valid, so return TRUE when we
    +        // find one.
    

    Regarding changing the logic back to d7. Beside earlier disagreements in the issue, I agree now, especially because we just support the single usecase currently, this change is what we want. What matters is to make it possible to see information, those would be otherwise exposed on the site most probably anyway.

  2. +++ b/core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php
    @@ -0,0 +1,118 @@
    +    // Test a term that exists in only one vocabulary.
    +    $this->assertTrue($view->argument['name']->setArgument($this->term2->getName()));
    +    $this->assertEqual($view->argument['name']->getTitle(), $this->term2->label());
    +    $view->argument['name']->validated_title = NULL;
    +    $view->argument['name']->argument_validated = NULL;
    +
    +    // Test a term that exists in at least two vocabularies.
    +    $this->assertTrue($view->argument['name']->setArgument($this->term1->getName()));
    +    $this->assertEqual($view->argument['name']->getTitle(), $this->term1->label());
    +    $view->argument['name']->validated_title = NULL;
    +    $view->argument['name']->argument_validated = NULL;
    +
    +    // Pass in an invalid term.
    +    $this->assertFalse($view->argument['name']->setArgument(rand(1000, 10000)));
    +    $view->argument['name']->validated_title = NULL;
    +    $view->argument['name']->argument_validated = NULL;
    

    Yeah adding some test coverage for multiple passed in names would be nice, just to check/document what happens (it won't be splitted). Adding test coverage for the bundle filtering would be nice as well.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new2.3 KB
new11.12 KB

56.1 Not quite sure what you mean. Is it ok as it is, or should we change anything?

56.2 Added two tests.

dawehner’s picture

56.1 Not quite sure what you mean. Is it ok as it is, or should we change anything?

Yes, it is okay. I was just thinking loud.

+++ b/core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php
@@ -109,10 +118,23 @@ public function testArgumentValidatorTermName() {
+
+    // Test filtering by bundle by passing a term from a vocabulary that is not
+    // in the bundle settings.
+    $this->assertFalse($view->argument['name']->setArgument('nonbundle'));
+    $view->argument['name']->validated_title = NULL;
+    $view->argument['name']->argument_validated = NULL;

What about adding the term to two vocabularies, one which is allowed and one which isn't as well?

lendude’s picture

+++ b/core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php
@@ -0,0 +1,140 @@
+    // Test a term that exists in at least two vocabularies.
+    $this->assertTrue($view->argument['name']->setArgument($this->term1->getName()));
+    $this->assertEqual($view->argument['name']->getTitle(), $this->term1->label());
+    $view->argument['name']->validated_title = NULL;
+    $view->argument['name']->argument_validated = NULL;

that's this one, was already in there, might need to update the comment to make that a little more clear

dawehner’s picture

that's this one, was already in there, might need to update the comment to make that a little more clear

Oh interesting, but I thought about the case where this is valid ... when the term actually exists.

lendude’s picture

Sorry, I don't follow your line of thought. In that test the terms actually exists in both vocabularies, one that is in the the bundle settings, and one that isn't.

dawehner’s picture

Please call be stupid, but why is this then an invalid term name?

duaelfr’s picture

Status: Needs review » Needs work

Is it a simple way in Core to deny access to a particular taxonomy term? It'd make that test easier.

stborchert’s picture

Dumb question: does using the term name validator works for you using the patch? I mean, the path is working fine and fixes the validator in general, but ... the term name is never converted to a term ID and this filters the result query using a wrong value.
Using the validator and a simple term reference field as argument, the query looks like this:
WHERE (( (node__field_channel.field_channel_target_id = 'ideas' ) ) ...

In Drupal 7 we had an additional option how to handle the argument ("Filter value type"). Do we want to convert the term name always to the ID or do we need to implement the value type selector?

stborchert’s picture

Added the conversion to always use the term ID.

bès’s picture

@stBorchert did you use a term name argument ? To do so you should add a relationship to a taxonomy reference field. Then choose "Taxonomy term: Name" contextual filters, using this relationship.

If you choose a "Has taxonomy term ID" filter or others it is not relevant to try using the taxonomy term name validator.

stborchert’s picture

No, I've used the term field directly without any reference. I expected it to work, since Drupal 7 acted like this ...

Saphyel’s picture

In D7 the behaviour was you get a name and it'll be convert to an ID, right?

if in D8 we know that looking for ID is working fine... why duplicate code?

bès’s picture

In my case I really want to validate term name and not term ID, so I don't see the problem to have a "term validation name" when the goal is to test that the term name passed to the filter match the good condition (that it could to be in multiple vocabulary for instance). If you use term ID you can't do that since it referrer to only one term.

I can see that maybe having the choice of irrelevant validation method is a problem, but it's not the frame of this issue. You could also choose to validate your term name with file ID or role validator and it will obviously don't work, but it's a views UI issue.

stborchert’s picture

Ok, I see the point here.
So its either using different validators for different requirements (TermNameToTid, etc.) or implement something like the type-selector as in Drupal 7.

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.

boobaa’s picture

Status: Needs work » Needs review
StatusFileSize
new11.12 KB
new699 bytes

Rerolled @stBorchert's patch from #65 without the term name to term ID conversion.

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.

duaelfr’s picture

Version: 8.3.x-dev » 8.4.x-dev
Issue tags: +DevDaysSeville
StatusFileSize
new11.01 KB

Rerolled against 8.4.x

duaelfr’s picture

I did some manual testing while writing the steps to reproduce and reviewed the coding standards while rerolling.
If the testbot is OK, it should be good to go.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

rjg’s picture

#76 has been working for us for many months.

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

dww’s picture

Agreed, this validator is definitely not working as expected. Especially when used with the most obvious possible contextual filter: core's "Has taxonomy term ID". In D7, there was a single taxonomy term validator that let you choose the style of validation you wanted, and it had an option for 'Term name converted to Term ID' which is actually what you want (since it leads to the most efficient queries). Sadly, all that is (for now) gone from D8 core.

I'd like to completely fix this at some point, consolidate all the term-related argument validation into a single plugin that lets you configure what kind of validation (and optional transformation) you want. It would simultaneously let this use case work smoothly, and simplify the UI by removing the 2 different 'Taxonomy term name' and 'Taxonomy term ID' choices (presented to all possible contextual filters).

Until then, for anyone else who needs the good ole' 'Term name converted to Term ID' functionality, enjoy:

https://www.drupal.org/project/views_taxonomy_term_name_into_id

malcolm_p’s picture

The patch in #75 is working for me as well. I'm testing against a very basic case that fails currently with a term name in 2 different vocabularies.

This bug can be very confusing for site builders so hopefully we can get this into 8.6 before code freeze.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

tea.time’s picture

I encountered this and it definitely caused a good moment of confusion for me too.

The patch in #75 still applied cleanly to 8.5.x and 8.6.x for me. It's working to resolve the same case, of a single-value argument validated against one vocabulary, and with two terms with the same name in different vocabularies.

dpagini’s picture

Status: Needs review » Reviewed & tested by the community

Considering #78, #81 and #83, I can also confirm this is working for me, and am bumping to RTBC for maybe the next step review...?

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
--- /dev/null
+++ b/core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php

+++ b/core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermNameTest.php
@@ -0,0 +1,135 @@
+/**
+ * Tests the plugin of the taxonomy: term argument validator.
+ *
+ * @group taxonomy
+ *
+ * @see Views\taxonomy\Plugin\views\argument_validator\Term
+ */
+class ArgumentValidatorTermNameTest extends TaxonomyTestBase {

This needs to be converted to use \Drupal\Tests\taxonomy\Functional\TaxonomyTestBase and moved to core/modules/taxonomy/tests/src/Functional/Views/ArgumentValidatorTermNameTest.php as WebTestBase tests are deprecated. At this point we should not be adding more.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alison’s picture

FWIW #75 still works great for me on 8.6.10!

rabbitlair’s picture

I would like to confirm #75 is working for me on 8.6.13.

knaffles’s picture

#75 works for me on 8.7.3.

alison’s picture

Issue tags: +Needs tests

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

alison’s picture

(#75 still works on 8.7.7!)

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

joey-santiago’s picture

Adding a patch with a working test for this.

mvantuch’s picture

I had raised the dupplicate #3029807 and can verify that as far as I can see, #75 is doing exactly the same thing as the patch I had provided there.

nikitagupta’s picture

Status: Needs work » Needs review
StatusFileSize
new11.29 KB
adambraun’s picture

#99 worked great. Attempting to mark Reviewed and Test by the Community.

adambraun’s picture

Status: Needs review » Reviewed & tested by the community

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 99: 2494617-99.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Needs review
StatusFileSize
new10.47 KB

I'm interested in helping to get this issue over the finish line. The latest patch has tests, but there are two problems with the tests:

1. They have never been run by the testbot without the fix applied
2. The tests could more closely imitate the tests for other argument_validators.

I'm attaching a test-only patch that uses the test View that is present in that latest patch (with the change of the name tags to views_testing_tags). I have removed the Functional test and replaced it with a Kernel test that is very closely modeled off of the test for the taxonomy term id argument validator. Kernel is faster than Functional, so this gains us speed in addition to consistency.

There's no interdiff because I don't think it would help.

Update: This is a long and winding issue, no? I just found comment #57 which included a test that is nearly identical to the one I added, and a slightly less ambitious one was added in #39. That one was even run as a test-only fail patch. Somehow that test got lost and was replaced with the Functional test that was still present in #99.

danflanagan8’s picture

StatusFileSize
new10.47 KB
new694 bytes

Fixing spelling...

Status: Needs review » Needs work

The last submitted patch, 105: 2494617-105-FAIL.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new11.88 KB
new1.41 KB

The new test failed just as anticipated. Removing the Needs tests tag.

Now I'm adding the fix from #99. This should pass.

danflanagan8’s picture

A couple things I'm thinking about now that I've spent more time reading through the issue:

  1. The test in #57 has a nice test about passing multiple names (which is not supported). It may be worth adding that in. (I essentially reproduced the patch in #57 independently in #104 and #105).
  2. There is discussion in #48 and #49 about a scenario involving certain permissions configurations. As far I as I can tell there was never testing related to this discussion but tests were suggested for this scenario.

We could go on all day with adding tests though. Part of the problem here is that there is apparently no existing (direct) test coverage for the taxonomy_term_name argument validator. So how much coverage do we need to add before we are happy committing this fix that has been used by many sites for many years? It's a tough situation.

danflanagan8’s picture

StatusFileSize
new15.29 KB
new4.79 KB

I figured it wouldn't hurt to just go ahead and bulk up the test coverage. Here's a new patch with more tests. If you look at the interdiff, you'll see that this is purely additions, with the exception of a changed comment. Therefore we don't need to do a new test-only patch.

I think the new access check tests give us a very good frame of reference for further discussion if we need it. There's a few more additions too including validation of multiple names (not supported) and tests that change the bundles array.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joey-santiago’s picture

Confirm the patch #109 works great. Thanks a lot!

joey-santiago’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 109: 2494617-109.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Reviewed & tested by the community

That was a random fail. Resetting status.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

  • catch committed d089745 on 10.0.x
    Issue #2494617 by Lendude, danflanagan8, Bès, Shreya Shetty, stBorchert...
  • catch committed 091a83d on 10.1.x
    Issue #2494617 by Lendude, danflanagan8, Bès, Shreya Shetty, stBorchert...
  • catch committed f462b56 on 9.4.x
    Issue #2494617 by Lendude, danflanagan8, Bès, Shreya Shetty, stBorchert...
  • catch committed d19fa67 on 9.5.x
    Issue #2494617 by Lendude, danflanagan8, Bès, Shreya Shetty, stBorchert...
catch’s picture

Version: 9.5.x-dev » 9.4.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs subsystem maintainer review

Committed/pushed to 10.1.x and cherry-picked back through to 9.4.x, thanks!

Removing the 'needs subsystem maintainer' review tag since both dawehner and lendude have reviewed this in the six years since that tag was added.

Status: Fixed » Closed (fixed)

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