Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I just noticed some PHP warnings on a D6 test site for a form that had a fieldset where '#collapsible' was TRUE and '#collapsed' wasn't defined. I thought '#collapsed' just defaulted to FALSE if you didn't specify it. See attached (trivial) patch. Applies with minor offset to D6, too. In D5 you need a different patch because of a code style error on the line below (missing a space).
Comment | File | Size | Author |
---|---|---|---|
#7 | drupal.fieldset.patch | 871 bytes | sun |
fapi_collapsed_not_defined.patch | 570 bytes | dww | |
fapi_collapsed_not_defined.d5.patch | 643 bytes | dww | |
Comments
Comment #1
Dave ReidShould we be accommodating for this misuse of the FAPI?
Comment #2
Dave ReidOh wait...nevermind. I read #collapsible and #collapsed backwards...
Comment #3
Dave ReidHmm...there are default values for #collapsible and #collapsed defined in system_elements:
Comment #4
dwwWell, tee hee, I see now I'm only getting the warnings in a place where I had done this:
Of course, now that I know, it's trivial to add
'#collapsed' => FALSE,
in there, but I don't see what's the harm in making the default theme_fieldset() get this right. It already successfully tests if #collapsible is defined, why not handle a missing #collapsed, too? Surely the !empty() isn't a performance concern, is it?Comment #5
sunHm. Did you think about using drupal_render() instead?
Comment #6
sunAnyway, I think we can fix this for D7. All FAPI tests pass. Additionally checked fieldset behaviors manually. Probably too minor to backport though, and I'd generally recommend the way in #5, since that will load the default element info for all element types.
Comment #7
sunActually, no - if we fix #collapsed, then we should also properly test for #collapsible.
Comment #8
Dave ReidDoes calling theme() on other $form type elements create errors as well? I'm still not convinced this needs fixing since we're not allowing default values from system_elements to get loaded in.
Comment #9
Dries CreditAttribution: Dries commentedCommitted #7 to CVS HEAD and DRUPAL-6. Thanks all!