It looks like in midst of porting this module to Drupal 8, the condition for checking the entity type in the subquery for the views argument handler was missed (see https://git.drupalcode.org/project/taxonomy_entity_index/-/commit/4d25cc...) even though the same condition was refactored and preserved in the views filter handler (see https://git.drupalcode.org/project/taxonomy_entity_index/-/commit/4d25cc...). Without checking the entity type, the contextual filter picks up seemingly unrelated entities.
Take the scenerio where media and content both have field_tags that use the Tags taxonomy. Also, where node:123 is tagged with your target term, and media:123 is not tagged with that term. If you have a view of all media using this term, media:123 will be included despite not being tagged with the term because 123 is an entity id in the subquery for the node (node:123) that is tagged with the term.
I could replicate it in a vanilla site with the following steps:
- In simplytest.me, enable media and this module.
- Add the tags field to the image media.
- Configure module to index both content and media.
- Created a node with nid = 1 with a tag (with tid = 2).
- Created media with mid = 1 without a tag.
- Create a view of all media.
- Add the contextual filter "Taxonomy Entity Index: Has taxonomy term ID on Media (with depth and indexed in taxonomy_entity_index)", and set the depth to 1 or more.
- View should be empty with the argument of 2, but media:1 is shown even though it has no tag.
Adding the below code to the argument handler (as in the case in /src/Plugin/views/filter/TaxonomyEntityIndexTidDepth.php:127) appears to resolve this issue:
if (isset($this->baseTableInfo['table']['entity type'])) {
$subquery->condition('entity_type', $this->baseTableInfo['table']['entity type']);
}
Comments
Comment #2
cainaruHere is a patch that adds the condition to the argument handler.
Comment #3
godotislateComment #4
larowlanThanks for this!
We have some tests in the module now, could you expand the existing test to demonstrate the bug. Thanks
Comment #5
cainaru@larowlan Sure! I've attached two patches—one is a test-only patch to demonstrate the bug, and the other patch is the full patch that includes both tests and the fix.
Comment #6
godotislate+1 RTBC
Comment #7
larowlanThis is looking great, only one minor change required and this can go in.
this needs to be taxonomy_entity_index
Thanks @cainaru, great work
Comment #8
cainaru@larowlan Thanks! Attached is a patch updated to use
@group taxonomy_entity_index, as well as an interdiff showing the changes between #5 and #8.Comment #10
larowlanCutting 1.4 tag with this in it, thanks!