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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Should we be accommodating for this misuse of the FAPI?

Dave Reid’s picture

Oh wait...nevermind. I read #collapsible and #collapsed backwards...

Dave Reid’s picture

Hmm...there are default values for #collapsible and #collapsed defined in system_elements:

  $type['fieldset'] = array(
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#value' => NULL,
    '#process' => array('form_process_ahah'),
  );

dww’s picture

Well, tee hee, I see now I'm only getting the warnings in a place where I had done this:

 $fieldset = array(
    '#title' => t('Table in a fieldset'),
    '#collapsible' => TRUE,
    '#value' => theme('table', $header, $rows),
  );
  return theme('fieldset', $fieldset);

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?

sun’s picture

Hm. Did you think about using drupal_render() instead?

$element = array(
  '#type' => 'fieldset',
  '#title' => t('Table in a fieldset'),
  '#collapsible' => TRUE,
  '#value' => theme('table', $header, $rows),
);
return drupal_render($element);
sun’s picture

Status: Needs review » Reviewed & tested by the community

Anyway, 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.

sun’s picture

FileSize
871 bytes

Actually, no - if we fix #collapsed, then we should also properly test for #collapsible.

Dave Reid’s picture

Does 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.

Dries’s picture

Version: 7.x-dev » 6.0
Status: Reviewed & tested by the community » Fixed

Committed #7 to CVS HEAD and DRUPAL-6. Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.