Views is not remembering default values for exposed filters. Steps to reproduce:
1. Create a view to list nodes.
2. Create an exposed filter on the Published field, make it non required and select a default value such as "No"
3. Save the view and go to the view's page.
4. The default value is not working.
5. Go back to editing the view and open the filter settings, the defualt value is gone (was probably never saved).
Displaying the right selected value is blocked by #1381140: A #default_value = 0 for #type radios checks all radios.
Because the boolean filter stores it value as a boolean the 'All' value can never be saved. It gets cast to TRUE. To facilitate the storing of the 'All' option, the boolean filter needs to store its values as a string.
Comment | File | Size | Author |
---|---|---|---|
#64 | boolean_default-40083.patch | 2.49 KB | larowlan |
#54 | boolean_default-2459289-52.patch | 62.59 KB | Lendude |
#54 | interdiff-2459289-47-52.txt | 448 bytes | Lendude |
#47 | interdiff-2459289-45-47.txt | 2.58 KB | Lendude |
#47 | boolean_default-2459289-47.patch | 61.95 KB | Lendude |
Comments
Comment #1
LendudeThe only value that seem to have a problem are boolean filters. Other filters that I tested seemed to work fine.
For the boolean values there are a couple of different things happening:
- Yes (value 1) works
- No (value 0) doesn't work. It's not saved but does shows up selected after clicking Apply and then opening the filter edit screen again. Opening the filter edit screen after save shows no selected radios.
- - Any - (value All) doesn't work but this gets interesting! When you select -Any- and apply and then open the filter settings again 'No' is selected (because of #1381140: A #default_value = 0 for #type radios checks all radios), and if you select -Any- apply this and save the view and then open the filter settings 'Yes' is selected! (I'm assuming this is because the value 'all' gets cast to 1 on save).
Comment #3
m.stentaI'm experiencing this too. Moving to 8.2.x.
Comment #4
LendudeThis is a bug fix so it can stay in 8.1.x for now.
Some of the findings we got in #2369119: Fatal error when trying to save a View with grouped filters using other than string values about this.
The problem seems to be that the exposed boolean filter value cannot be stored in a boolean field, this is because it can have 3 values (yes-no-all). The non-exposed boolean filter value only has 2 values, so that's fine.
Currently there is no way to use a different format for the exposed filter value then for the non-exposed filter value.
Two things I can think of to solve this:
1-Make it possible to set a different storage format in config for the exposed and non-exposed values.
2-Make the boolean filter alway store the filter value as a string
any other solutions?
Comment #5
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedHi,
I am looking into this. I am able to reproduce it on my local setup.
Comment #6
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commented@lendude : it seems to be the different issue, as the filters present on the exposed form is having 3 values while at the view preview page its showing 2 values. I think while making the filter exposed its forming 2 values instead of 3. is it the correct understanding?
Comment #7
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commented@lendude : my bad, i think its could solve the issue as suggested by you i will try to modify the scripts and let you know about this.
Comment #8
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #9
stBorchertChanging status.
Comment #11
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #12
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #14
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #15
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #17
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #18
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #20
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #22
andrewbelcher CreditAttribution: andrewbelcher at FreelyGive commented#2734197: FilterPluginBase::acceptExposedInput should check 'All' strictly has been postponed on this as @Lendude thinks this is the root cause, though from my testing I am not sure that is the case.
Comment #23
kalistos CreditAttribution: kalistos commenteddhrjgpt2005, did you mean this one?
Comment #24
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedHi Kalistos,
Thanks for the perfect patch.
Need to run this patch with 8.1 and 8.2 also needs to update some of the test cases.
I will be doing the fixes for the test cases soon.
Comment #25
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #27
HnLn CreditAttribution: HnLn commentedIs there any workaround for the moment ? If I do a form alter on views_exposed_form and set the default value to 'All', the default value still jumps to the first option (true). Tried setting it to to '- Any -' as well.
Comment #28
LendudeThanks for taking a look at this @dhrjgpt2005 but not sure if #23 is the way to go.
Here is my first stab at a fix. This converts the values for boolean filters to strings.
Couple of things:
Comment #30
LendudeThis should clear up some fails.
Comment #32
LendudeLets see if I got them all. Passes locally now.
Comment #33
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commented@lendude thanks for looking into this. I will verify this at my end too.
Comment #34
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #35
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commentedComment #36
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer commented@lendude: i tried to run the patch on 5.6 and it gets failed on 2 locations, so do we need to look into that as well.
Comment #37
dawehnerI would have expected that the boolean filter itself would have to be changed, now that we are using strings, instead of booleans. This might be a reason for the failure in 5.6?
Is there a reason we cannot use a post update here?
There might be instances with
1/0
out there, should we take into account them as well?Comment #38
dawehnerComment #39
LendudeSo would I, but the code that distinguishes between on and off in \Drupal\views\Plugin\views\filter\BooleanOperator::queryOpBoolean is
if (empty($this->value)) {
, so it doesn't matter is you give it FALSE, 0 or "0", it's all empty. It just works.37.1 Only reason was that I had no idea that existed, fixed.
37.2 Updated, it would be a bit weird to run into that because that would violate the current schema too, but who knows what's floating around out there.
Wrote a update test, but can't get it to pass locally, keeps timing out, so its completely untested so I don't have high hopes for it yet.
No idea yet why it fails on 5.6.
Comment #42
LendudeThis is probably to invasive to target 8.1.x, so moving to 8.2.x
lets see what this fixes.
Comment #43
LendudeComment #45
LendudeUpdate test passes locally now and some more views got added.
Moved the upgrade test view to fixtures folder so it won't cause a fail of TestViewsTest (since the whole point of the view is that it starts invalid). Other option would be to change TestViewsTest to allow a view to be ignored.
This patch will fail every time a new (test)view is committed that uses the status filter.
Comment #47
LendudeThe failing test was because
\Drupal\system\Tests\Update\UpdatePathTestBase::runUpdates
assumes that the config is up-to-date even when you have (and expected) failing updates. This seems strange to me, so I moved the config check into theif ($this->checkFailedUpdates)
so you only expect an up-to-date config when you expect no failing tests.Comment #48
dawehnerThat is totally logical
Comment #54
LendudeA new test view got committed so this was failing again.
Updated the new view.
This is going to be the reroll patch from hell :)
Comment #55
dawehnerThat is always a good thing
Comment #57
LendudeUnrelated fails, the fail on php 5.6 looks unrelated too.
Comment #58
catchWhat happens if a contrib module provides a view as default config using this filter? I see the test fails above with test views, but not clear if that translates to an actual user-facing/config install issue with an exported view.
Comment #59
dawehnerThis is not a concern here, because we don't change any runtime code. If something magically managed to save the right value, for example by manual changing things, they continue to work.
Comment #60
catchMakes sense. Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!
Comment #62
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer and at TATA Consultancy Services commentedComment #63
dhrjgpt2005@gmail.com CreditAttribution: dhrjgpt2005@gmail.com as a volunteer and at TATA Consultancy Services for Pfizer, Inc. commentedComment #64
larowlan8.1 reroll for those who're interested, credit to @welly