Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Discovered in #1324618: Implement automated config saving for simple settings forms:
Problem
- When setting
$form['#tree'] = TRUE;
and$form['#parents'] = array('foo');
on the top-level $form itself, Form API is unable to find its own required form_id, form_build_id, and form_token values in the submitted form values.
This is an edge-case usage scenario, for which I doubt it makes sense to write tests for.
Comment | File | Size | Author |
---|---|---|---|
#5 | drupal-1591726-5.patch | 1.59 KB | tim.plunkett |
#2 | drupal8.form-tree-parents.2.patch | 1.61 KB | sun |
drupal8.form-tree-true.0.patch | 1003 bytes | sun | |
Comments
Comment #1
sunSorry, forgot the totally important detail about also having custom #parents on the $form itself.
Comment #2
sunDiscussed with @chx that enforcing explicit #parents is better than #tree FALSE.
We also discussed whether the other form processing/validation code shouldn't rather check for $form['form_token']['#value'] instead of relying on submitted form values, but that would inherently add a dependency on the $form structure. Out of the two choices, enforcing #parents made more sense.
Comment #3
chx CreditAttribution: chx commentedGood to go.
Comment #4
Dries CreditAttribution: Dries commentedI reviewed this patch but it was not 100% clear. Given that both chx and sun approved it, and that all tests pass, I committed it anyway.
Comment #5
tim.plunkettRerolled.
Comment #6
sunThanks!
Comment #7
David_Rothstein CreditAttribution: David_Rothstein commentedI had trouble getting my head around this one too. Ultimately, I think it just comes down to the fact that there's lots of code in the form API that looks for these things in the top level of $form_state['input'] or $form_state['values'], so we need to ensure that they will actually always be in the top level.
Out of curiosity, why? I would have found this code a lot easier to understand with #tree set to FALSE, because that's the standard way to accomplish the above. Is the concern that someone altering the form might be likely to change #tree by accident?
Anyway, this patch works fine as is, so although it seems like there might be room for a followup to clarify the code comments, etc.... I committed it to 7.x. Thanks!
http://drupalcode.org/project/drupal.git/commit/121b348
Comment #8.0
(not verified) CreditAttribution: commentedUpdated issue summary.