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.
The current API doc for hook_forms show this function as not taking any parameters, which is wrong.
In D5, it takes any $args
the caller of drupal_retrieve_form()
chose to pass. See form.inc/drupal_retrieve_form()
.
In D6 and D7 until UNSTABLE-5, it takes a $form_id
and the same $args
as in D5.
Comment | File | Size | Author |
---|---|---|---|
#16 | 405832.patch | 3.76 KB | jhodgdon |
#12 | 405832.patch | 3.76 KB | jhodgdon |
#9 | 405832.patch | 4.4 KB | jhodgdon |
#7 | 405832.patch | 3.78 KB | arianek |
#4 | 405832.patch | 3.78 KB | jhodgdon |
Comments
Comment #1
fgmNote that the D5->D6 migration guide includes a bit of information about this change : http://drupal.org/node/144132#hook-forms
Comment #2
add1sun CreditAttribution: add1sun commentedMoving to correct queue.
Comment #3
jhodgdonNote that hook_forms() is called from http://api.drupal.org/api/function/drupal_retrieve_form , which in turn is called from drupal_get_form() (with an intermediate function drupal_build_form() in Drupal 7).
In Drupal 5, the input args to drupal_retrieve_form() are $form_id and flexible additional arguments passed into drupal_get_form(). The arguments passed to hook_forms() are the form ID and the additional flexible arguments. Documentation of hook_forms() doesn't make this clear, in my opinion.
In Drupal 6, the input args to drupal_retrieve_form() are $form_id, $form_state, and the flexible arguments from drupal_get_form(). $form_state is removed from the arg list before calling drupal_retrieve_form() in Drupal 6 -- so hook_forms() works like Drupal 5 (form ID plus flexible arguments). Documentation of hook_forms() doesn't make this clear, in my opinion.
In Drupal 7, the input args to drupal_retrieve_form() are form ID and form state. What is passed to hook_forms() in D7 is $form_id, plus the 'args' component of $form_state, which actually comes from the flexible arguments of drupal_get_form(). This is almost correctly documented in the hook_forms() documentation, except that it doesn't make clear that $form_id is not in the $args array.
Also, the Drupal 7 documentation for drupal_retrieve_form() incorrectly implies that drupal_retrieve_form() takes the additional flexible arguments, but this is incorrect -- drupal_get_form() puts these into $form_state['args'] and the flexible arguments are not passed in that form to drupal_retrieve_form(). So the item for "additional ... arguments" should be removed from the Drupal 7 documentation of drupal_retrieve_form().
So, in my opinion, D7 needs a small patch for hook_forms() and one for drupal_retrieve_form(), and D6/D5 need completely different patches for hook_forms().
Comment #4
jhodgdonHere is a patch for Drupal 7 for review.
Comment #6
jhodgdonThis is a doc-only patch. Submitting for retest, as there is no way this patch caused tests to fail.
Comment #7
arianek CreditAttribution: arianek commentedreuploading for bot
Comment #8
c960657 CreditAttribution: c960657 commentedThe lines are wrapped at considerably less than 80 characters. There is no reason to make them that short.
Comment #9
jhodgdonHere's a new patch, with some additional cleanup of wording, and wrapping at closer to 80 characters.
Comment #10
sunI'll review this after API freeze.
Comment #12
jhodgdonHere's a new patch, which should apply.
Comment #14
arianek CreditAttribution: arianek commentedin the modules/system/system.api.php section, should "drupal-form_submit" be "drupal_form_submit"?
Comment #15
jhodgdonYes, needs a new patch to fix that. thanks!
Comment #16
jhodgdonHere's a patch with that typo fixed.
Comment #17
aspilicious CreditAttribution: aspilicious commented#16: 405832.patch queued for re-testing.
Comment #18
aspilicious CreditAttribution: aspilicious commentedIt still applies (on my local machine) and looks good!
So if bot doesn't hate me this is RTBC
Comment #19
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #20
jhodgdonSee #3 above -- this also needs to be fixed in Drupal 6 and Drupal 5. Not a simple patch port, though.
Comment #21
jhodgdonMoving to docs queue for hook files
Comment #22
sven.lauer CreditAttribution: sven.lauer commentedThis has actually been fixed by #574284: Documentation problem with hook_forms, I think.