Problem/Motivation
#1168246: Freedom For Fieldsets! Long Live The DETAILS. changed the implementation of Drupal’s collapsible widgets from using <fieldset> elements to using the HTML5 <details> element. One of the consequences of this is that the Form API '#group' property (designed for implementing vertical tabs, and which only ever worked with fieldsets) now only works with <details>. However, since <details> is not appropriate in all the situations in which fieldsets were used in Drupal 7, situations arise where <details> can't be used, but '#group' is in play.
An example of this is the node add/edit form. It’s been redesigned for D8 and does not use vtabs anymore. However, many modules add their fields to a secondary settings area using the #group property. This group of secondary fields is not intended to be collapsible, so the functionality and semantics of <details> isn’t appropriate. But not using details causes the form to break (fields are not grouped and their weights scatter them throughout the node form).
Proposed resolution
Determine whether the #group property should a) be extended to work with <fieldset>s as well as <details>, b) be extended to work with any form element, or c) find another solution to the resulting problems.
API Changes
- Add new form_pre_render_group() which contains the logic for groups which is currently in form_pre_render_details()
- Add form_pre_render_group() where applicable, type #container to begin with
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 1856178-11.patch | 8.76 KB | swentel |
| #10 | 1856178-10.patch | 6.24 KB | swentel |
| #9 | 1856178-9.patch | 3.46 KB | swentel |
| #4 | 1856178-4.patch | 1.93 KB | swentel |
Comments
Comment #1
sunWhile working on the details patch, I noticed that Views UI apparently implements its own #fieldset_group property to move form controls into the three columns that make up the Views view admin UI.
The logic that is going on in there seems to be fairly similar to core's #group for details (formerly fieldsets). I suspect that this was added to Views, either because its new interface design got implemented before #group existed, or because Views was not aware of it.
Anyway, my bottom line is:
We should turn the #group facility into a ultra-generic thing.
It has proven itself to work really well for grouping into vertical tabs, and its implementation is mature - the logic accounts for many special cases (e.g., handling for the case where the specified #group does not exist, properly handling access, and properly handling empty groups [i.e., not rendering the grouping container when it does not contain any [accessible] groups], etc.pp.).
Therefore, I think we want to move the entire logic belonging to #group from the current details-related callbacks into separate callbacks for #group handling, and then, add the callbacks to the element info that need them (i.e., details, fieldset, perhaps even container).
Comment #2
ry5n commentedIt makes sense to make this capability generic. The flip side though is should we use the #group mechanism to achieve that, or something else? (Render arrays? See #1016918: Vertical tabs should use common renderable structures, not extra #group property.) I don't have enough expertise to have an opinion, but I thought I'd bring it up for consideration.
Comment #3
swentel commentedGoing to try this, because it's probably going to be a blocker to commit #1838114: Change node form’s vertical tabs into details elements. See this lovely screenshot.
Comment #4
swentel commentedHere's a patch that allows container also to group elements.
API changes
Two things that Sun can probably answer or help with:
Screenshot posted here
Comment #6
swentel commented#4: 1856178-4.patch queued for re-testing.
Comment #7
sunWow! @swentel, you rock hard. I didn't expect the baseline for this to be *that* simple. :)
Though perhaps that only underlines even more what I stated in #1 already — the entire #group functionality is pretty mature and relatively abstracted already.
To complete this patch, we need to add isolated (DUTB) tests, which prove that we're able to assign #group nilly-willy and get what we want.
As an addition test case, we could eliminate Views' custom #fieldset_group property - although that's a lot of code (but perhaps also only a search+replace?) - so not sure whether that should be a separate follow-up.
re: #4:
1) Yeah, let's just remove/replace the references to details.
2) form_pre_render_details() actually contains an early-return right before the #group processing, since the entirety of that depends on #parents, which exists within a Form API context only. So I think what we want to do is:
- Split that #pre_render callback into two: form_pre_render_details() + form_pre_render_group()
- Apply form_pre_render_details() + form_pre_render_group() to the #type definition for details (in this order).
- Apply form_pre_render_group() to the #type definition for container.
3) Not sure why you chose "groups" (plural). Since the render property is #group (singular), I'd actually prefer to go with singular callback names, too, so that there's a direct relationship.
4) The general concept seems to be that #group works for "container"-alike element #types. Should this also work for #type fieldset? Anything else?
Comment #8
ry5n commented@sun @swentel Awww, YES! I am so happy to hear this. With this kind of patch I’d just be a third wheel, but I can at least check the form API RE: #7 point 4). The only other #type this might apply to is `actions`, although that might be a special case. #type vertical_tabs should already work, unless this patch would change that.
Comment #8.0
ry5n commentedAdded code tags to make talk of markup visible.
Comment #9
swentel commentedNew patch. I think I addressed all points, except for 4 (only applied it to type #container right now) and no tests yet. I'm assuming DUTB is for unit tests or something alike, and do we have them for details already somewhere ? Don't have time for tests though today anymore, will be something for this weekend (or possible maybe a little tomorrow), unless someone beats me to it.
I've do the views as a follow up though.
Comment #10
swentel commentedAnd now with tests. It took me a while to find a good place to add tests, hope it's ok :)
Comment #11
swentel commentedAnd fieldset can now use #group as well. Added tests for vertical tabs as well. This could go RTBC fast imo.
Comment #12
sunLooks good to me.
The test should have been a DrupalUnitTestBase (DUTB), since we don't really need a browser/request to build + process + render a form, but we can clean this up later on.
Thanks!
Comment #13
webchickNice! Great to see these patches to help along the content creation page.
Committed and pushed to 8.x. Yay! :)
I think we need a change notice for this?
Comment #14
swentel commentedChange notice added here: http://drupal.org/node/1891074
Comment #15
swentel commentedComment #17
xjmUntagging. Please remove the "Needs change notification" tag when the change notice task is complete.
Comment #17.0
xjmUpdated issue summary.
Comment #18
anybody