As initially reported by kbahey at http://drupal.org/node/138706#comment-244726 (comment #118 of the original FAPI3 issue):
Reading the documentation that is here http://drupal.org/node/144132 I find something that really needs to be fixed: the function prototypes have asymmetric argument ordering.
For example, for *_form_alter() we have $form_values, $form_id, $form_state, but for *_validate() we have $form_id, $form_values, $form_state. For *_submit() we have $form_id, $form_values, $form_state.
It would be best for everyone if we have a general consistent order for the arguments, for example, $form_id, $form_values followed by $form_state. This would make the learning curve less steep, as well as reduce confusion and errors.
Dries, myself, and many others agree we should do this. However, http://drupal.org/node/138706 has become impossible to follow, so I'm submitting this as a separate issue so we can start fresh.
Comment | File | Size | Author |
---|---|---|---|
#27 | comment.module_77.patch | 751 bytes | ax |
#21 | upload.module_44.patch | 812 bytes | ax |
#15 | fapi_install.patch | 1.21 KB | eaton |
#7 | form_params.patch | 57.63 KB | eaton |
Comments
Comment #1
kbahey CreditAttribution: kbahey commentedObviously, I give this a +1.
Think of all the newbies ...
Comment #2
eaton CreditAttribution: eaton commentedchanging the hook_form_alter() parameters won't work; it relies on the first parameter being passed by reference and thus MUST be $form. That was part of the change to use drupal_alter() rather than custom iterators every time we needed to alter a FAPI-like structure. (links, menus, profiles, etc).
Alter functions and submit/validate functions really do accept a different set of params, so things aren't quite as clear cut. What we could do is standardize on this order:
$form, $form_state, [$form_id | $form_values]
That would ensure that $form and $form_state are always the first parameters, while the 'different' bits come at the end.
Any thoughts?
Comment #3
dwwthat sounds pretty reasonable to me. my only question is: "what FAPI-related functions don't take a form_id, and why not?" ;) seems like we *could* pass the form_id everywhere, even if it's not technically required. then, we could just have the order be something like:
form, form_id, form_state, [form_values]
Comment #4
chx CreditAttribution: chx commentedeaton++ . form_id passing in to validate/submit--
Comment #5
eaton CreditAttribution: eaton commentedRight now, hook_form_alter() is actually the only place that needs $form_id -- we now use the id to retrieve the form, but no longer do switching logic based on form_id in the submit and validate handlers.
Comment #6
dwwgreat, that's fine with me. keeping everything 3 args deep is nice, for consistency, too. ;) so, i remove whatever percieved hesitation #3 might have emplied, and fully embrace/support #2.
Comment #7
eaton CreditAttribution: eaton commentedhere's a quick roll of the patch -- DEFINITELY needs testing.
Comment #8
David StraussThanks for taking care of the dirty work necessary to make the interface consistent.
Comment #9
David StraussHopefully this patch will get more attention and testing with this new title. I had to read the thread to realize what this issue was actually about.
Comment #10
Dries CreditAttribution: Dries commentedI'd like this to go in, so hopefully, we can get some testers here! :)
Comment #11
morphir CreditAttribution: morphir commented+1
I have tested this one, and everything seems just fine.
Comment #12
morphir CreditAttribution: morphir commentedalso,
make sure that handbook-pages on coding standard gets updated.
Comment #13
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #14
morphir CreditAttribution: morphir commentedthere is a fugly bug in the install process.
Comment #15
eaton CreditAttribution: eaton commentedInstall.php was hard-calling the user module's internal FAPI functions, and that line had been missed. Fixed!
Comment #16
morphir CreditAttribution: morphir commentedworks!
Comment #17
dmitrig01 CreditAttribution: dmitrig01 commentedconfirmed
Comment #18
robertDouglass CreditAttribution: robertDouglass commentedConfirmed. Thanks Eaton.
Comment #19
Dries CreditAttribution: Dries commentedCommitted. Thanks.
Comment #20
ax CreditAttribution: ax commentedline 917
$form = form_builder('upload_js', $form, array());
breaks my site with a "PHP Fatal error: Only variables can be passed by reference". so either
array()
should be a variable or&$form_state
infunction form_builder($form_id, $form, &$form_state) {}
should be changed to$form_state
.Comment #21
ax CreditAttribution: ax commentedarray()
should be$form_state
. patch attached.Comment #22
drewish CreditAttribution: drewish commentedit does seem like $form_state should be passed in but if its omission wasn't a bug, i'd be a fan of something like:
Comment #23
ax CreditAttribution: ax commentedi'm pretty sure the omission *was* a bug, as $form_state is defined just the line above. fixed with my patch at #21.
Comment #24
yched CreditAttribution: yched commentedFollow up bugfix : args reordering for form submit handlers needs to be reflected in batch engine.
Patch submitted in http://drupal.org/node/147501
Comment #25
ax CreditAttribution: ax commentedplease commit the remaining typo fix, #21 at http://drupal.org/node/146470#comment-251011 . tnx!
Comment #26
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #27
ax CreditAttribution: ax commentedanother follow-up fix, this time in comment.module. hope thats the last one :S
Comment #28
dwwthat patch scares me. what's the difference between
$form_state['values']
and$form_values
? i fear the answer is: "none, they're identical". i remember eaton saying he wanted to get rid of $form_values entirely. if it's completely duplicate with $form_state['values'], it seems like we should just finish removing it completely before the API freeze, both to avoid developer confusion, and to reduce the memory footprint of passing around big, redundant arrays all over the place.p.s. @ax: for future reference, it's considered bad form to post your own patch as RTBC. your own work is always "needs review" until independently verified by someone else. thanks. in this case, i'm setting it back to needs review since i'd like eaton and/or chx's input on this topic of standardizing the hook parameters by way of removing
$form_values
entirely.Comment #29
eaton CreditAttribution: eaton commentedWe can definitely kill $form_values. It's redundant and only serves as a convenience -- I'd be happy to see it removed. Given how close we are to the freeze, however, I'd want to roll that change in with http://drupal.org/node/146667 -- fixing problems with $form_state in parameterized builder functions. Given how late we are in the cycle I have no desire to start mucking around with numerous mutually exclusive patches.
it's a reference, not a copy, so there's no memory penalty, but all other arguments for removing it stand.
Comment #30
ax CreditAttribution: ax commented@dww:
> p.s. @ax: for future reference, it's considered bad form to post your
> own patch as RTBC. your own work is always "needs review" until
> independently verified by someone else. thanks.
i know, and i usually do (see #21 above). point is, "needs review" often rots in the queue (see #25 above), and i don't have the time to follow up on these. in this case - where a obvisious typo completely breaks something, here: the comment submission - i just did the same as yched at #24 (and me at #25) above: post the patch and set it to RTBC so it gets attention. so in 2 out of 3 cases (and after eatons #29, i'd say in 3 out of 3 cases) i guess this was the right thing to do, because otherwise we would still have a broken HEAD.
of course it would be better to get attention for critical patches in "need review" state, but thats another issue.
Comment #31
dwwlet's call this fixed and move our attention to eaton's latest patch at http://drupal.org/node/146667
Comment #32
(not verified) CreditAttribution: commentedComment #33
dharamgollapudi CreditAttribution: dharamgollapudi commentedSubscribing....