Closed (fixed)
Project:
Drupal core
Version:
8.2.x-dev
Component:
views.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Jan 2016 at 19:41 UTC
Updated:
27 Jul 2017 at 15:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mikeker commentedThe underlying issue is that at core/modules/views/src/Plugin/views/filter/FilterPluginBase.php:1351, we check that the exposed input is an empty array, but a bunch of unchecked checkboxes results in an array of zeros. Thus the filter is added to the query when it shouldn't be.
Patch coming shortly...
Comment #3
mikeker commentedThis is blocking the D8 port of Better Exposed Filters.
Comment #4
dawehnerComment #5
mikeker commented@dawehner, I was afraid you would say that... :)
Comment #6
mikeker commentedAdds rudimentary tests.
Comment #10
mikeker commentedAck... I included my debug code by accident.
Comment #11
mikeker commentedComment #12
dawehnerIdeally we could check in that function whether we are dealing with checkboxes here, but this is not really possible, sadly.
Comment #13
mikeker commented@dawehner: yeah, I couldn't find a good way to do that.
We could move this to \Drupal\views\Plugin\views\filter\InOperator::acceptExposedInput(). It would be better scoped there, I suppose.
Comment #14
dawehnerMaybe we could provide a method in the base class and call it from there? It seems that this method could be helpful for more than one place
Comment #15
mikeker commentedAfter talking the @dawehner in IRC, we decided to provide a detectEmptyCheckboxes() function in FilterPluginBase and move the validation of that input into InOperator.
Working on an updated patch.
Comment #16
mikeker commentedThis change has the odd side-effect of moving the docblock/code style updates to FilterPluginBase::acceptExposedInput out of scope (as there are no longer any code changes to that function). I would like to suggest that we accept those doc changes anyhow, but can remove them if the powers-that-be object.
Comment #17
mikeker commentedClosing #2623312: Default value of "any" gives empty results in Drupal 8.x as a dup of this.
Comment #18
akalata commentedUpdating steps to reproduce
Comment #19
akalata commentedUpdating steps to reproduce, again
Comment #20
akalata commentedI've manually tested #16. Can confirm the presence of the bug as reported, and that the fix makes checkboxes work as expected, without breaking the default multiselect.
Comment #22
Torenware commentedTest failure appears to have been a transient test bot issue.
Comment #23
catchAdding related issue
Why public? Shouldn't this be protected?
Also this feels like something form API should provide. I've added the #options issue as related, which might make the general problem go away, but even without that feels like a FAPI issue that we could add a helper there for.
Comment #24
mikeker commented@catch, thank you for the review.
Yes it should. Fixed. I also updated the comment to more accurately state what is returned when checkboxes are checked.
Agreed. But #342316: Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent. is using a Twig template for each select #option (which has serious performance issues), adds two new FAPI elements, and has generally lost momentum any number of times since it was opened in 2008. You're right, this approach is working around an inconsistency in FAPI's handling of #options, but I'm concerned that the other issue will never be finished because of all it's extra baggage. (Edit: fixed bad grammar.)
This issue blocks the most common use-case for the Better Exposed Filters module: using checkboxes instead of multi-selects. I can't really release a beta of BEF on D8 until this is fixed. Also, shouldn't #342316: Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent. be a 8.1.x issue since it's an API change?
@catch, if you feel strongly against this approach, I'll jump in the other issue and see if I can restart that discussion.
Comment #25
mikeker commentedSorry, forgot the interdiff.
Comment #26
amateescu commentedI think what @catch means is that we could move this helper method to
\Drupal\Core\Render\Element\Checkboxesas a static method.Comment #27
dawehnerToday chx and I talked about this problem and had a slightly nicer idea to solve the problem. The idea was to add an
_=query parameter in the expose dform, anddetect by that whether the views form was actually submitted. This would have just to be added for forms with checkboxes ... so its seems to be not disruptive.
Comment #28
mikeker commented@dawehner, I considered that workaround but I really don't like it. We spend so much effort getting pretty URLs (eg: we allow users to specify the filter ID) that it would be a shame to make them ugly again. It feels like a kludge.
@amateescu: Ahhh... That makes sense. I'll post an updated patch. Thanks.
Comment #29
mikeker commentedComment #30
amateescu commentedThe
_=query parameter will break in this scenario:- user checks an option and submits the form
- user unchecks that option and submits again
- now the URL will contain the
_query param (because the form was submitted), but all checkboxes will be unchecked and we're back to the initial problemI'm afraid there's also another problem with the current patch, it doesn't fix the issue completely. Specifically, if the view is paged and the user navigates to the next page when all checkboxes are unchecked, the much-dreaded
An illegal choice has been detected. Please contact the site administrator.shows up and no view results are displayed.Initially, I posted a patch in the BEF queue (#2687773: Using checkboxes with an "is all of" filter fails if any options are selected), but, on second thought, the paging problem should be fixed by this patch as well. I updated the tests to include this scenario but I'm not yet sure what's the best place to filter the user input for empty checkboxes in core.
Comment #32
mikeker commentedI'll spend some time this afternoon on this.
In my initial look, I think we should move the check for empty checkboxes back into FilterPluginBase. In this case the "type" filter uses Bundle instead of InOperator. I can only imagine there will be other filter plugins that will have the same issue. Basically I'm flip-flopping what I said in #13... :)
Comment #33
mikeker commentedOK, that took a bit longer than I expected... :)
I believe I've solved the problem with the pager links not working. And it raised a few other issues in the process. There is currently a bug where clicking the pager link with an exposed form option selected will add a bogus
&=Filterquery string argument. (The#valueof the submit button gets added to the pager links.) While it may sound like issue scope-creep, it's the same underlying problem: that checkboxes are handled so differently than multi-select elements.And, yes, to @catch's point in #23, this should be handled by the FormAPI, but that is going to be a big lift while this needs to be fixed in order for BEF to get a release. I am reiterating my hope that we can fix this in a limited scope and remove these workarounds when #342316: Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent. is resolved.
So, this patch:
Checkboxes::getCheckedCheckboxes$view->exposed_raw_inputto include just the checked checkboxes (which fixes the "illegal choice" error)Comment #34
amateescu commentedThanks @mikeker! I found a couple of small things that should be fixed and I'll let @dawehner comment on the views parts.
This comment needs to be re-wrapped to 80 chars.
We should use
static::here.Comment #35
mikeker commented@amateescu, Thanks for the review!
Man, I can never keep those straight!
Comment #36
dawehnernitpick: empty() always returns a boolean
It would be great to have a todo + an issue to handle that on a more fundamental level, aka. the GET form, not sure whether this is even feasible though.
Note, we use
{@inheritdoc}, but sure what the exact difference is, but its just how it is.Comment #37
dawehnerComment #38
mikeker commented@dawehner, thanks for the review!
I've fixed #1 and #3.
I added an @TODO for #2, but I'm not sure that the best issue to link it. Thoughts?
Comment #39
dawehnerYeah that issue seems not really super targeted ... not sure though about a better one either. Maybe we should simply create a new one?
Comment #40
vivianspencer commentedThis patch works great, but causes a fatal error when used with taxonomy lists that have a hierarchy.
I get the following errors:
Recoverable fatal error: Object of class stdClass could not be converted to string in Drupal\Component\Utility\Xss::filter() (line 72 of /vagrant/web/core/lib/Drupal/Component/Utility/Xss.php).
Warning: strlen() expects parameter 1 to be string, object given in Drupal\Component\Utility\Unicode::validateUtf8() (line 691 of /vagrant/web/core/lib/Drupal/Component/Utility/Unicode.php).
Comment #41
xjmBased on the API additions, this issue is potentially only allowed during minors; however, given its impact on BEF (an important contrib project) @Cottser, @effulgentsia, @alexpott, and I agreed to consider whether this is an RC target.
@alexpott also said that he would like subsystem maintainer review for this patch.
Comment #42
xjmMeant to add the rc target triage tag.
Comment #43
vivianspencer commentedThe reset button doesn't work with this patch
Comment #44
catch#40 and #43 both sound like CNW.
Comment #45
tim.plunkettI need to step through this with a debugger, but here's an initial review of the patch itself.
If this needs a reroll, please change to
public staticDoes this run after
\Drupal\Core\Render\Element\Checkbox::valueCallback()? I believe it does, just sanity checkingLowercase @todo, indent the second line by 2 spaces
Needs tests for #40/#43
Comment #46
mikeker commentedFrom #40:
That is by design. Taxonomy filter options come as objects and need to be converted to strings. This should happen in the same place you're changing the element type.
re: #43 (reset button doesn't work): I'll look into that.
re: #45: Thanks for the review @tim.plunkett. I'll address those items shortly.
Comment #47
mikeker commentedAttached patch addresses #45.1 and .3.
No.
Checkboxes::valueCallback()runs beforeCheckbox::valueCallback(). Though I'm totally in the dark as to what this implies... :)re: #43:
I wasn't able to reproduce this. Note that the reset button does not appear until a filter value is specified. Can you provide steps to repro?
Also, since #40 is by-design, I'm removing the Needs tests tag. Let me know if there was another use-case that needed tests that I missed.
I would reassign this to @tim.plunkett, but I don't have permissions to do that. Thank you @xjm for bumping this to Major and considering it for 8.1 RC.
Comment #48
cybercraft2003 commentedHi guys,
I've got the same problem with my custom exposed form module.
I want to resolve this without modify the core.
Someone have a hint ?
Comment #49
mikeker commented@Cybercraft2003, at this point, the only way for this to work correctly is to apply the latest patch to core or wait for the fix to be accepted into core. The best way to move this forward it to test the patch and report your results here.
Thanks.
Comment #50
lokapujyaThis seems done.
I also can't reproduce the issue with the reset button.
Comment #52
mikeker commentedRerolled #47.
Comment #55
mikeker commentedNot sure why the testbot is running the patch against 8.1, re-uploading in hopes that it'll run it against 8.2...
Comment #56
akalata commentedComment #57
ipwa commentedTested patch and works well for me. Looking forward to this patch being committed so BEF can start working on a D8 release. Good work guys!
Comment #58
catchA few small things, otherwise looks OK to me.
The comment is the opposite of the method name - should both be either positive or negative.
Looks out of scope.
all options
but? Should it be 'by?'.
Comment #59
mikeker commented@catch, Thank you for the review!
#1: Fixed. Also updated the @param comment to match that in
getCheckedCheckboxes()#2: Kinda... I figured I was changing the code in that function so I should update the docblock to meet coding standards. I can remove it -- let me know.
#3: Sorry, I don't understand...
#4: Fixed.
Comment #60
lokapujyaall options
Comment #61
mikeker commented@lokapujya, thanks! Didn't see that.
Comment #62
dawehnerI really like the solution. I mean its a workaround, but its a workaround for a bug (IMHO) in all major browsers.
Could we link to same place which explains the weirdness of GET checkboxes? I think this would be a great resource for people.
Nice!
Comment #63
mikeker commentedComment #64
lendudeWe got tests, we got a fix, all feedback from #58, #60 and #62 is addressed.
Manually tested that with this applied, non-checkbox filters keep working like they should.
Comment #65
catchPHPCS isn't happy with the test .theme file.
Tagging novice for those changes.
Comment #66
gaurav.pahuja commentedComment #67
gaurav.pahuja commentedGiving it a try.
Comment #68
lendudeNitpick: White space error
Comment #69
sagar ramgade commentedRemoved the white space, patch and interdiff attached.
Comment #71
mikeker commentedI think the previous patch was diff'ed against a branch that already had an earlier patch applied, thus the newly added files were not marked as such. This is #67, minus the whitespace, diff'ed against 8.2.x.
Comment #72
mikeker commentedSorry, misnamed the interdiff. It is against #67, not #69.
Comment #73
lendudeFeedback from @catch has been addressed, looks good again.
Comment #74
luksakFor me the reset button isn't working either when used in combination with views_exposed_filters. I am running on 8.1.2 and I tried using the patches in #47 and #71. I tried to reproduce this on 8.2.x without success. Does anyone know how to solve this for 8.1.x? Otherwise leaving RTBC for 8.2.x.
Comment #75
mikeker commented@Lukas von Blarer, if the reset button is working correctly with the latest version of core, then the issue has been fixed between 8.1.2 and 8.2.x. It may be possible to backport that fix to 8.1.x, but that is not part of this issue and should be dealt with separately.
Thanks.
Comment #76
luksakAbsolutely. Just thought if anyone knew a quick answer to this, it would haven been quite helpful to me :)
Comment #77
catchCommitted d1ae9b7 and pushed to 8.2.x. Thanks!
Comment #80
thomas.fleming commentedI don't know if there is any intention to backport this fix to 8.1.x, but here is a re-roll of #78 for 8.1.x. I can confirm that the patch works in 8.1.3.
Comment #81
thomas.fleming commentedComment #83
thomas.fleming commentedMy reroll was missing core/modules/views/tests/themes/views_test_checkboxes_theme/. Testing again.
Comment #84
thomas.fleming commentedComment #85
vivianspencer commented@tidrif Your patch works for me, except for the reset button
Comment #86
lendudeThis patch as it currently stands contains API changes so it isn't eligible for 8.1.x, that's why it was moved to 8.2.x, see Allowed changes for what can and can't be changes in certain versions.
So unless somebody does a major rewrite for 8.1.x that doesn't contain the API changes, this will have to remain a 8.2.x only fix.
Comment #87
mikeker commentedReturning to what this issue was as of #79. If someone does the rewrite needed to get this into 8.1.x, please feel free to reopen.
Comment #88
luksakThere are some issues introduced by this. Would be nice to get some feedback on #2687773: Using checkboxes with an "is all of" filter fails if any options are selected.
Comment #89
sukanya.ramakrishnan commentedSubmitting a patch for the issue reported in #88 for 8.2
Comment #90
sukanya.ramakrishnan commentedSubmitting a patch against the reroll patch for 8.1 in #83 and an interdiff!
Thanks
Sukanya
Comment #91
sukanya.ramakrishnan commentedComment #93
sukanya.ramakrishnan commentedsorry, started tests against the wrong version and status changed to needs work! changing to needs review again!
Comment #94
mikeker commented@sukanya.ramakrishnan, this is a closed issue that has already been committed. Can you explain what you're trying to fix? I'm guessing this would be better handled in a separate issue.
Comment #95
dawehnerPlease open a new issue for new patches. Otherwise its super hard to discuss stuff.
Comment #96
sukanya.ramakrishnan commentedThanks for your time and guidance. Submitted the patch in this issue https://www.drupal.org/node/2687773#comment-11546257
Issue is that upon pager navigation, checkbox values are not retained!
Comment #97
xjmComment #98
gg4 commented