In D6, fieldsets could be used in a non-form context - CCK's fieldgroup heavily relied on this, e.g fieldgroups in displayed nodes.
With 'vertical tabs' addition In D7, form_pre_render_fieldset() contains code specific to a form context ($element['#parents']; $element['#groups'], populated in form_process_fieldset(), executed only in form arrays), and raises warnings when a fieldset is used in a non-form render array.
Side note : vertical tabs, heavily relying on #process, cannot be included in non-form render arrays, which is sad (VTs, like JS tabs or accordions, are a valid candidate for non-form presentation - see #824812: Future of fieldgroup - call for volunteers
Comment | File | Size | Author |
---|---|---|---|
#38 | drupal-857124-38.patch | 2.04 KB | tim.plunkett |
#35 | drupal-857124-35.patch | 2.07 KB | tim.plunkett |
#30 | drupal-non_form_fieldsets_rerolled-857124-30.patch | 2.13 KB | lucascaro |
#26 | drupal-non_form_fieldsets_rerolled-857124-26.patch | 4.16 KB | lucascaro |
#23 | drupal-non_form_fieldsets_rerolled-857124-23-test-only.patch | 781 bytes | lucascaro |
Comments
Comment #1
yched CreditAttribution: yched commentedfix title
Comment #2
sunDuplicate of #740834: Form elements cannot be rendered without form_builder() ? Just a bit more focused, it seems. Perhaps we should keep 'em separate.
Comment #3
fagoI was able to get it rendered that way:
Comment #4
sunSo I wonder whether all of the current collapsible logic shouldn't be moved entirely into a (new) #pre_render for #type 'fieldset' ?
From a technical POV, I think this would make sense. If you'd feed me with enough ice-cream, I'd probably fix vertical tabs very similarly in a few hours, too.
Comment #5
mcreature CreditAttribution: mcreature commentedsubscribing
Comment #6
sunI'm resolving #740834: Form elements cannot be rendered without form_builder() currently. But let's keep the general issue of being able to render form elements separate from the two specific collapsible fieldsets + vertical tabs cases, as those are much more complex. I.e., #740834 will only prepare theme_fieldset() to work without form_builder(), but that does not solve the problem that only #pre_render and no #process callbacks are invoked -- which should be solved for the two use-cases here.
Changing title and component accordingly.
Comment #7
yched CreditAttribution: yched commentedfix title ? :-)
Comment #8
Alan D. CreditAttribution: Alan D. commentedIt does seem like an easy fix for the fieldsets by simply moving the few lines of code in the #process function into the #pre_render function. This additional behavior is conceptually just a decoration to the element and it has no bearing on functionality.
The patch with limited testing is found here in #740834: Form elements cannot be rendered without form_builder().
Fixing the groups seem like a slightly bigger job, maybe it is worth creating two separate issues to get these fixes in, with minimal changes to the API to keep webchick happy. :)
Comment #9
Stalski CreditAttribution: Stalski commentedsubscribe
Comment #10
Stalski CreditAttribution: Stalski commentedIn field_group module, i've got the vertical tabs working (without form_state memory). I'll commit the code very shortly.
So if i can help here in this issue. I don't like ofcourse what i needed to do, but had to see it working for myself.
Screenshot attached.
Comment #11
sunHappy to review a patch. ;)
Comment #12
Stalski CreditAttribution: Stalski commented@sun well, that's when i need guys like you. What can be done? I see a couple of opportunities but mostly i am fond of what you have said in another issue: let the vertical tabs be "processed" in the theme layer, certainly not in the form.api.
So, since the fieldset stuff is calculated in the form api only AND the bad part, keeping track in the form_state, my first proposition is to move those tracking variables in the form as #properties. Can this be done you think?
But i would be happy to try to write a patch, but i would have to know a couple of things:
- what is covered? vertical tabs and fieldset processing for non-form builds.
- What are the boundaries? I forsee that some code needs to go out form.inc and goes into ... ? common.inc ?
- Can we introduce something? E.g. having the $form_state as special exception of a build_state if you know what i mean. So non-form builds could always have a tracking state object too (or array). Vertical tabs default tab could depend on this.
What do you think?
Comment #13
Stalski CreditAttribution: Stalski commentedThis is not a patch yet, but i want somebody to walk with me here.
The following array just work as expected while building a non-form.
So what exactly is the key here.
[#parents] => Array (additional_settings) This made it work for non-forms, however, if this property exists on the form build ... i got an endless loop. So a little fix while building the element on my behalf fixes that, no problem there.
So the question remains, if we want to remember default tabs and so for non-form things, we need a way like form properties or an equivalent of form_state for non-form builds.
Comment #14
HylkeVDS CreditAttribution: HylkeVDS commentedsubscribe
Comment #15
jcarlson34 CreditAttribution: jcarlson34 commentedSubscribing
Comment #16
Alan D. CreditAttribution: Alan D. commentedI just hit the same issue again. This was the patch from the mentioned thread above for the fieldset part of this issue.
It is a bit stale as it was created a year ago. Seeing if it applies and passes current tests.
Comment #18
Alan D. CreditAttribution: Alan D. commentedDuh. That patch was really old. Here is D8 git patch
Comment #19
xjmTagging as novice for the task of rerolling the Drupal 8.x patch on account of #22336: Move all core Drupal files under a /core folder to improve usability and upgrades.
If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.
Comment #20
30equals CreditAttribution: 30equals commentedHey hey,
attached is the rerolled patch as requested. Let's go testbot!
Comment #21
xjmThanks @30equals, the reroll looks great!
Can we add an automated test for this? The test would fail without the patch in #20 and pass with it.
Comment #22
lucascaro CreditAttribution: lucascaro commentedLooking into making a test for this issue.
Comment #23
lucascaro CreditAttribution: lucascaro commentedok, here's a test that checks for the presence of the class "collapsible" which is added after the patch is applied. I'm not sure if this is enough as a test for this issue, so pleas advise.
I'm attaching the patch with tests only (should fail) and the patch from #20 plus the test, and this should pass.
Comment #24
tim.plunkettTrailing whitespace here (and in the test only patch too, of course)
Not setting back to CNW yet.
Comment #25
lucascaro CreditAttribution: lucascaro commentedthanks @tim.plunkett , I had seen that and corrected it on my local copy but didn't upload a new patch yet. Good to have it on the record though.
Besides that, do you think it's enough to test for the collapsible class or we'd need to check for the inclussion of the javascript as well?
Comment #26
lucascaro CreditAttribution: lucascaro commentedHere's the patch again, with tests and the white space removed.
Comment #28
xjmThanks @lucascaro. Looks like the patch is malformatted; it has some doubles of some lines--could you try recreating it?
Comment #29
lucascaro CreditAttribution: lucascaro commented#23: drupal-non_form_fieldsets_rerolled-857124-23.patch queued for re-testing.
Comment #30
lucascaro CreditAttribution: lucascaro commentedw00t!
sorry, I don't know why that happened.. here's a new patch
Comment #31
xjmAlright, I think this test and fix are sufficient. Thanks @lucascaro!
Comment #32
lucascaro CreditAttribution: lucascaro commentedgreat!
Comment #33
catch#30: drupal-non_form_fieldsets_rerolled-857124-30.patch queued for re-testing.
Comment #35
tim.plunkettJust broken because the file was moved in #1299424: Allow one module per directory and move system tests to core/modules/system, no change.
Comment #36
catchComment #37
catchThanks. Committed/pushed to 8.x.
This looks backportable to me.
Comment #38
tim.plunkettStraight backport.
Comment #39
xjmTagging for posterity.
The backport matches and there are no UI changes other than "it's not broken."
Comment #40
webchickThis looks safe, but since it smells of API change, I'd like to hold it until after this week's release.
Comment #41
David_Rothstein CreditAttribution: David_Rothstein commentedLooked this over, and I agree with @webchick that this smells of a possible API change.
For Drupal 7, wouldn't it be possible to duplicate the code in form_pre_render_fieldset(), rather than moving it there? (And by "duplicate" I don't necessarily mean duplicate exactly, of course; rather, "check if X was already added to the array, and if not, add it now", that kind of thing.)
Seems like that would be a safer way to achieve the same effect, no?
Comment #42
pfrenssenA workaround for people who want to render collapsible fieldsets in D7 now: you can make it work by adding the right classes and loading the javascript files:
Comment #43
mgiffordLooks like we need a patch with the workaround.
Comment #46
sukanya.ramakrishnan CreditAttribution: sukanya.ramakrishnan commentedI believe this patch is for fieldsets to work without forms right?
Can someone help me regarding where i can find info about making vertical tabs work without form builder?
Thanks a ton,
Sukanya
Comment #47
martini9011 CreditAttribution: martini9011 commented@sukanya.ramakrishnan I managed to add vertical tabs outside of a form using the following code in a page callback function (invoked through hook_menu()).
I'm guessing the same logic also can be applied in other places, such as preprocess functions etc. since this just uses the render and theming engine.
Comment #50
k4v CreditAttribution: k4v commentedI also think its sad ;) that I cannot use vertical tabs in D8 outside of forms. Whats the current state of this issue?