Problem/Motivation
In views module there are some collapsible details elements that are displayed empty at the moment.
For example: Having moved the "administrative title" field (as in Views 7.x) to its own collapsible details, the section "More" does not contain any options in most cases.
Lookin into this issue we found a problem in the views module: It still uses its own logic to group widgets ('#fieldset') -- while most of the containers already have been converted to details elements.
The details element has a mechanism to hide empty fieldsets, but it does not work for direct children in the container element.
Proposed resolution
We decided to fix the UI problem by using the available option on the details container. Removing all fieldset logic is out of scope for this issue here.
Remaining tasks
none.
Original report by @hexabinaer
Comment | File | Size | Author |
---|---|---|---|
#99 | views-more-3.png | 30.47 KB | tstoeckler |
#99 | views-more-2.png | 30.71 KB | tstoeckler |
#99 | views-more-1.png | 30.48 KB | tstoeckler |
#85 | hide_empty_details-2409639-85.patch | 8.53 KB | k4v |
#84 | assert_more_is_absent.patch | 685 bytes | k4v |
Comments
Comment #1
katzillaadded patch.
Comment #2
katzillaComment #3
k4v CreditAttribution: k4v commented.
Comment #4
k4v CreditAttribution: k4v commentedComment #6
hexabinaerOoops, seems to be more complicated than I thought. Please provide summary of sprint weekend findings/discussions. I know of:
* should be solved programmatically (thus: issue title changed)
Settings this to unassigned, for I am not the one capable of solving. katzilla and k4v are working on it.
Comment #7
k4v CreditAttribution: k4v commentedComment #8
dawehnerIt would be great if someone could post a screenshot of what we are talking here
Comment #9
k4v CreditAttribution: k4v commentedAnother try.
Comment #10
k4v CreditAttribution: k4v commentedComment #11
dawehnerIts great to see that we finally have an api for that in core. ... so can we remove the preRender function from views after that?
Comment #12
k4v CreditAttribution: k4v commentedThis was quite confusing. I still wonder, why I have to set
'#parents' => array('more')
on the details element.Comment #13
tstoeckler@k4v: Awesome idea using #parents, nice one!
Re #11: Yes, in theory we can remove PluginBase::preRenderAddFieldsetMarkup() and all of it's usages now, I think.
Comment #14
k4v CreditAttribution: k4v commentedoops
Comment #16
k4v CreditAttribution: k4v commentedComment #17
k4v CreditAttribution: k4v commentedHere's a new version with all the fieldset stuff removed.
Comment #18
k4v CreditAttribution: k4v commentedComment #20
dawehnerReally nice cleanup! Sadly still a php error :)
Comment #21
k4v CreditAttribution: k4v commentedOnce again.
Comment #22
k4v CreditAttribution: k4v commentedComment #24
k4v CreditAttribution: k4v commentedlets try this....
Comment #25
k4v CreditAttribution: k4v commentedComment #27
tstoeckler@k4v: The patch looks great. Two things are making the tests fail, apparently:
1.
FilterPluginBase
(line 518) andSortPluginBase
(line 205) expect#pre_render
to be set, which is no longer the case so that leads to PHP errors.2. The tests rely on the
#parents
form structure to set the form values, so they are trying to set form values of the formoptions[foo][bar]
when it should now be justfoo[bar]
because we have explicitly removedoptions
from the parents. See the test results for exactly where that happens.Comment #30
k4v CreditAttribution: k4v commentedI did some research on the subject "fieldset vs details" in the issue queue.
'type' => 'fieldset' has been widely replaced by 'type' => 'details': https://www.drupal.org/node/1168246
Views uses a strange mixture of both at the moment: The '#fieldset' property is a special thing views does to sort the leaf elements into the 'fieldsets', but in our case it has already been replaced with a 'details' container element.
What I did in #9 is not the right thing. The #group property is only valid for elements of type details and fieldset, not for the leaf elements.
Comment #31
k4v CreditAttribution: k4v commentedAnother approach. To remove the #fieldset logic complete should be a new issue.
Comment #32
dawehnernote: better use static::groupHasNoChildren and protected. This makes it al little bit easier to override the logic in a subclass.
Comment #33
k4v CreditAttribution: k4v commentedComment #35
k4v CreditAttribution: k4v commentedComment #36
Gábor HojtsyLooks like this needs resolved before this may land.
Is it true if it does not have parents, it does not have children either?
Comment #37
tstoecklerThat is not true. See
NodeForm
for proof. I think #24 was really close and preferable to the current patch.Comment #38
k4v CreditAttribution: k4v commentedSee: https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...
Searching for '#type'=>'details' I see in almost all of the examples that the children are added to the details directly.
=). I still like #35 better -- why not put the leaf elements right there where they belong?
Comment #39
tstoecklerRe #36.2: The check for the children that are directly contained in the element is done prior to that check:
$children = Element::getVisibleChildren($element); if (empty($children) ...)
. This is not very intuitive (not @k4v's fault, but Form API's), but it's correct. At least I think it makes sense. This needs an issue summary update, I hope I get to that later today. I will also try to polish the inline code-comments a bit and open some follow-ups for this.Most importantly this needs review from a Views maintainer. I don't know why the fieldset dance was originally introduced into Views, so we should check before altering it. Not sure how old this is in Views (so maybe only @dawehner can help here?) but I will ping someone on the VDC team to have a look at this.
Comment #40
k4v CreditAttribution: k4v commentedComment #41
k4v CreditAttribution: k4v commentedComment #42
dawehnerWell, this dance was introduced in order to decouple the rendered form structure from the form structure/parents structure itself.
Comment #43
tstoeckler@dawehner: So that means you (also) prefer to go back to the patch in #24?
Comment #44
k4v CreditAttribution: k4v commentedAnother simpler variant would be to use the #group property (like in #24) and set it to '#group' => 'options][more'.
This is the most simple thing to do, then we don't need to change the #parent structure, and the logic for #optional shuld work. It's done like this in several places, like CKEditorPlunginManager, Line 167.
Still, the form api documentation says its only for details and fieldsets...
Comment #45
tstoecklerInteresting about
CKEditorPlunginManager
I wasn't aware of that. Ok, let's got with that then, since we have a precedent?!Comment #46
dawehner+1
Comment #47
k4v CreditAttribution: k4v commentedI just re-tested #24 and it does not work, the elements are not added to the group.
Either I did some stupid mistake back then or something changed by now.
Could someone in charge of the form api look into this? I don't really understand how the #group, #parents and #optional are meant to work.
Comment #48
k4v CreditAttribution: k4v as a volunteer commentedAnother try at Drupalcon Barcelona =). After discussing this again with tstoeckler, he proposed this solution.
Comment #50
k4v CreditAttribution: k4v as a volunteer commentedfix this
Comment #51
k4v CreditAttribution: k4v as a volunteer commentedgo testbot
Comment #53
k4v CreditAttribution: k4v as a volunteer commentedhmm
Comment #54
k4v CreditAttribution: k4v as a volunteer commentedComment #57
k4v CreditAttribution: k4v as a volunteer commentedComment #58
k4v CreditAttribution: k4v as a volunteer commentedComment #61
madhavvyas CreditAttribution: madhavvyas as a volunteer and at CIGNEX commentedNot sure about what is the use of "option][more" means? Please explain its significance
Comment #62
madhavvyas CreditAttribution: madhavvyas as a volunteer and at CIGNEX commentedFixed some coding standard issues
Comment #65
k4v CreditAttribution: k4v as a volunteer commented@madhavvyas: we need "#group" => "options][more' because this is the mechanic of the #group property. It has to contain the complete path to the root of the form, with the strange '][' as separators.
I tried to throw out #fieldset entirely, but the tests fail because there are still other places that use #fieldset.
Not sure if we can change them all to use #group.
Comment #66
tstoecklerAhh @k4v nice catch!!! Very right you are. So let's just remove those hunks that remove the '#fieldset' functionality and just keep everything related to the 'more' stuff here. That should get us to a green patch. Then we can discuss removing the '#fieldset' stuff in a follow-up, but I fear that's D9 material at this point.
Comment #67
madhavvyas CreditAttribution: madhavvyas as a volunteer and at CIGNEX commentedSorry for that, I have reverted 'options][more' change as per patch provided by @k4v in comment #57
Comment #68
madhavvyas CreditAttribution: madhavvyas as a volunteer and at CIGNEX commentedPlease dis-regards my last patch file it has some extra change due to rebase. Updating original Patch with 'options][more' changes.
Comment #71
k4v CreditAttribution: k4v as a volunteer commented@madhayvvas: thanks =).
I put the fieldset-code back in.
Comment #72
k4v CreditAttribution: k4v as a volunteer commentedeven simpler
Comment #73
k4v CreditAttribution: k4v as a volunteer commentedComment #74
tstoecklerThe coding style changes introduced in #62 and following are a bit distracting in general, but some of the instances like the ones shown above a simply incorrect, so I don't think the patch can go in like this. Can we have a patch that's more like #57, but with all the #fieldset stuff reinstanted?
Comment #75
k4v CreditAttribution: k4v as a volunteer commentednew patch without the code style changes.
Comment #78
tstoecklerThanks a lot, verified again that this fixes the problem
Comment #81
k4v CreditAttribution: k4v as a volunteer commentednot sure what happened here, putting it back to RTBC, the test is still green.
Comment #82
dawehnerAs said, we need some tests.
Comment #83
dawehnerComment #84
k4v CreditAttribution: k4v as a volunteer commentedThis test should be red here, I include it in the following patch to show its green then.
Comment #85
k4v CreditAttribution: k4v as a volunteer commentedThis should be green. Yay.
Comment #86
k4v CreditAttribution: k4v as a volunteer commentedComment #89
k4v CreditAttribution: k4v as a volunteer commentedComment #90
tstoecklerLooks good to me.
Comment #93
madhavvyas CreditAttribution: madhavvyas as a volunteer and at CIGNEX commentedLooks good to me too!
Comment #94
k4v CreditAttribution: k4v as a volunteer commentedComment #95
alexpottThere is still plenty of use of
#fieldset
in views...We either need an issue summary update or more change. Which feels risky given the where we are at in the release cycle and benefits of this change.
Comment #96
k4v CreditAttribution: k4v as a volunteer commentedComment #97
tstoecklerYes, the updated issue summary makes it clear that this is only a bug fix and no API change is involved. We went that route with earlier patches, but no more.
Comment #98
alexpottSome before and after screenshots of the UI would be nice.
Comment #99
tstoecklerHere we go.
Comment #100
alexpottCommitted 458f5be and pushed to 8.0.x. Thanks!
Thanls for the screenshots and issue summary update.
Comment #102
katzillaYeah - finally! Great work @all :-)
Comment #103
dawehneryeah!!
Comment #104
k4v CreditAttribution: k4v as a volunteer commentedFollowup to possibly remove #fieldset everywhere: https://www.drupal.org/node/2581255