When building a new form element items such as #tree or #process don't seem to get propagated to the forms API. This can be seen for the date form element in core.

Comments

Robrecht Jacques’s picture

StatusFileSize
new1.75 KB

The #process seems to propage correctly.
The #tree doesn't.

Tested with module attached where I would expect #tree => TRUE to be set on the $element, so the output (when submitting) would have $form_values['foo']['part1'] instead of currently $form_values['part1'].

This bug (?) can be avoided by putting $element['#tree'] = TRUE; in expand_mytest().

ricabrantes’s picture

Version: x.y.z » 7.x-dev

Any news about this? moving to d7.x...

brianV’s picture

Gerhard - is this issue still relevant?

casey’s picture

Yup, #tree => TRUE in hook_element_info() is still not working:

#tree => TRUE is used in system_element_info() for $types['checkboxes'], but #tree => TRUE is also being set in form_process_checkboxes(). When I comment out the latter, #tree functionality on checkboxes is gone.

So it's still not working.

#process in hook_element_info() works fine.

casey’s picture

Title: hook_elements does not seem to work correctly. » #tree in hook_element_info does not work
effulgentsia’s picture

If it weren't for the setting of #tree=>TRUE for the 'checkboxes' type in system_element_info(), I'd be tempted to mark this "by design". If we want to make hook_element_info() support #tree, doing so would be easy: within form_builder(), this code:

if (!isset($element[$key]['#tree'])) {
  $element[$key]['#tree'] = $element['#tree'];
}

could be modified to check element_info(), because this code runs for the child element ($element[$key]) before form_builder() is called for that child element, and therefore, defaults haven't been merged in yet.

But I'm not sure supporting #tree in hook_element_info() is a good idea, or at any rate, I'd like a compelling use-case. It seems to me that #tree should be set at the point that child elements are added. Usually, in a form constructor or a #process function. In the example module from #1, I think it makes more sense to set it in the #process function than in hook_element_info(). When is it ever a good idea to set it in hook_element_info()?

Any thoughts on this? If there's agreement that the behavior of HEAD is correct, let's roll a quick patch to remove the unnecessary and misleading line from system_element_info(). If there's a good use-case for letting #tree be specified in hook_element_info(), let's identify it and roll a patch with it as a test.

fago’s picture

Agreed. I don't think setting #tree makes sense there except when one uses #process. Then setting it during processing makes imho more sense, as else the constructor could have set it differently already.

Also see #759222: #tree does not default to TRUE, fails to meet developer expectations for fixing nested uses of #tree.

sun’s picture

Status: Active » Postponed (maintainer needs more info)

This should be fixed now due to #482816: Make a consistent wrapper around submit buttons

Please confirm that this is still an issue.

sun’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.9 KB

Let's see what breaks.

effulgentsia’s picture

StatusFileSize
new2.19 KB

How about this instead? I agree with making it *possible* for hook_element_info() to set #tree, since we also allow hook_element_info() to set #name, #value, and similar properties, that there are few if any good use-cases for doing. But I'm not convinced that we actually want to shift the setting of #tree of checkboxes from the #process function to the hook_element_info() function. If you believe we should, how about arguing for that in a separate issue, and letting this one be just about removing what is probably an unintended exception of what can be done in hook_element_info()?

sun’s picture

Status: Needs review » Reviewed & tested by the community

Works for me :)

effulgentsia’s picture

Status: Reviewed & tested by the community » Fixed

This apparently went in on http://drupal.org/cvs?commit=368076.

Status: Fixed » Closed (fixed)

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