In an Entity Field Query view I have an exposed filter on the Bundle property. I have selected a couple of bundles as default value and I have selected the "Limit list to selected items" option. "Allow multiple selections" is disabled and the filter is not required.

The exposed filter is displayed as a dropdown select list with the default value being "- Any -". When this value is selected, I expect only the default bundles that I selected to be used for the query, but instead all items are shown, so no filtering is taking place.

In the code of the handler views_handler_filter_in_operator, the method accept_exposed_input contains the following:

   // If this is non-multiple and non-required, then this filter will
    // participate, but using the default settings, *if* 'limit is true.
    if (empty($this->options['expose']['multiple']) && empty($this->options['expose']['required']) && !empty($this->options['expose']['limit'])) {
      $identifier = $this->options['expose']['identifier'];
      if ($input[$identifier] == 'All') {
        return TRUE;
      }
    }

The problem is that there is no expose setting 'limit'. I think that the "Limit list to selected items" setting was meant here, but that setting has key 'reduce'. When I change 'limit' to 'reduce', the filter behaves like expected.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jorrit’s picture

Status: Active » Needs review
FileSize
1.39 KB

Please see attached patch.

Jorrit’s picture

The following patch contains just the test, so it must fail.

Status: Needs review » Needs work

The last submitted patch, views-in-filter-default-value-test-only-1704372-2.patch, failed testing.

Jorrit’s picture

Status: Needs work » Needs review
dawehner’s picture

To make it perfect here is a patch which merges the two above, just to be sure that the patch even fixes the new tests.

I'm impressed that you created a test even noone asked you to do so, this happens really really rarely.

Jorrit’s picture

Thanks, I should have done that too. I saw that Views already has a lot of tests, so adding one was a matter of copying the existing test for this handler and modifying the specific conditions. If I had to write a test from scratch, I probably wouldn't have done it, because the code to setup a test is quite extensive.

Chris Matthews’s picture

Assigned: Jorrit » Unassigned
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 6 year old patch in #5 does not apply to the latest views 7.x-3.x-dev and if still applicable needs a reroll.

Checking patch handlers/views_handler_filter_in_operator.inc...
Hunk #1 succeeded at 292 (offset 27 lines).
Checking patch tests/handlers/views_handler_filter_in_operator.test...
error: while searching for:
      'views_test_age' => 'age',
    ));
  }
}

error: patch failed: tests/handlers/views_handler_filter_in_operator.test:94
error: tests/handlers/views_handler_filter_in_operator.test: patch does not apply
Jorrit’s picture

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

Rerolled and test added.

Chris Matthews’s picture

Thanks Jorrit, the rerolled patch in #8 fixes this issue for me, but it may need another review before changing the status to RTBC so I'm leaving the status as is for now.

Jorrit’s picture

I accidentally misnamed the patch file. I am reuploading it with the right name.

Chris Matthews’s picture

The renamed patch in #10 is still good for me.