diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php index efa51916dd..899e23eab1 100644 --- a/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php @@ -218,4 +218,47 @@ public function testExposedFilter() { $this->assertTrue(empty($preview), 'No results.'); } + /** + * Tests using the TaxonomyIndexTid in a filter group. + */ + public function testFilterGrouping() { + $node_type = $this->drupalCreateContentType(['type' => 'page']); + + // Create the tag field itself. + $field_name = 'taxonomy_tags'; + $this->createEntityReferenceField('node', $node_type->id(), $field_name, NULL, 'taxonomy_term'); + + // Create 2 nodes: 1 without a term and 2 with different terms. + $this->drupalCreateNode(); + $this->drupalCreateNode([ + $field_name => [['target_id' => $this->terms[1][0]->id()]], + ]); + $this->drupalCreateNode([ + $field_name => [['target_id' => $this->terms[2][0]->id()]], + ]); + + // Create two groups. The first group contains the published filter and set + // up the second group as an 'OR' group for two different terms. + $view = View::load('test_filter_taxonomy_index_tid'); + $display =& $view->getDisplay('default'); + $display['display_options']['filters']['tid']['value'][0] = $this->terms[1][0]->id(); + $display['display_options']['filters']['tid']['group'] = 2; + $display['display_options']['filters']['tid_2'] = $display['display_options']['filters']['tid']; + $display['display_options']['filters']['tid_2']['id'] = 'tid_2'; + $display['display_options']['filters']['tid_2']['value'][0] = $this->terms[2][0]->id(); + $display['display_options']['filter_groups'] = [ + 'operator' => 'AND', + 'groups' => [ + 1 => 'AND', + 2 => 'OR', + ], + ]; + $view->save(); + + $this->drupalGet('test-filter-taxonomy-index-tid'); + $xpath = $this->xpath('//div[@class="view-content"]//a'); + // We expect both nodes with terms but not the node without a term. + $this->assertIdentical(2, count($xpath)); + } + } diff --git a/core/modules/views/src/ManyToOneHelper.php b/core/modules/views/src/ManyToOneHelper.php index cb2e5754a8..6921799196 100644 --- a/core/modules/views/src/ManyToOneHelper.php +++ b/core/modules/views/src/ManyToOneHelper.php @@ -308,18 +308,18 @@ public function addFilter() { $placeholder .= '[]'; if ($operator == 'IS NULL') { - $this->handler->query->addWhereExpression(0, "$field $operator"); + $this->handler->query->addWhereExpression($options['group'], "$field $operator"); } else { - $this->handler->query->addWhereExpression(0, "$field $operator($placeholder)", [$placeholder => $value]); + $this->handler->query->addWhereExpression($options['group'], "$field $operator($placeholder)", [$placeholder => $value]); } } else { if ($operator == 'IS NULL') { - $this->handler->query->addWhereExpression(0, "$field $operator"); + $this->handler->query->addWhereExpression($options['group'], "$field $operator"); } else { - $this->handler->query->addWhereExpression(0, "$field $operator $placeholder", [$placeholder => $value]); + $this->handler->query->addWhereExpression($options['group'], "$field $operator $placeholder", [$placeholder => $value]); } } }