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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fgm’s picture

Project: Drupal core » Documentation
Version: 7.x-dev » 6.x-1.x-dev
Component: documentation » Correction/Clarification
Status: Reviewed & tested by the community » Active
Issue tags: -API clean-up

Note that the D5->D6 migration guide includes a bit of information about this change : http://drupal.org/node/144132#hook-forms

add1sun’s picture

Project: Documentation » Drupal core
Version: 6.x-1.x-dev » 7.x-dev
Component: Correction/Clarification » documentation

Moving to correct queue.

jhodgdon’s picture

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

jhodgdon’s picture

Status: Active » Needs review
FileSize
3.78 KB

Here is a patch for Drupal 7 for review.

Status: Needs review » Needs work

The last submitted patch failed testing.

jhodgdon’s picture

Status: Needs work » Needs review

This is a doc-only patch. Submitting for retest, as there is no way this patch caused tests to fail.

arianek’s picture

FileSize
3.78 KB

reuploading for bot

c960657’s picture

The lines are wrapped at considerably less than 80 characters. There is no reason to make them that short.

jhodgdon’s picture

FileSize
4.4 KB

Here's a new patch, with some additional cleanup of wording, and wrapping at closer to 80 characters.

sun’s picture

Issue tags: +API clean-up

I'll review this after API freeze.

Status: Needs review » Needs work

The last submitted patch failed testing.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
3.76 KB

Here's a new patch, which should apply.

jhodgdon requested that failed test be re-tested.

arianek’s picture

in the modules/system/system.api.php section, should "drupal-form_submit" be "drupal_form_submit"?

jhodgdon’s picture

Status: Needs review » Needs work

Yes, needs a new patch to fix that. thanks!

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
3.76 KB

Here's a patch with that typo fixed.

aspilicious’s picture

#16: 405832.patch queued for re-testing.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

It still applies (on my local machine) and looks good!

So if bot doesn't hate me this is RTBC

Dries’s picture

Project: Documentation » Drupal core
Version: 6.x-1.x-dev » 7.x-dev
Component: Correction/Clarification » documentation
Status: Active » Fixed
Issue tags: +API clean-up

Committed to CVS HEAD. Thanks.

jhodgdon’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Active

See #3 above -- this also needs to be fixed in Drupal 6 and Drupal 5. Not a simple patch port, though.

jhodgdon’s picture

Project: Drupal core » Documentation
Version: 6.x-dev »
Component: documentation » API documentation files

Moving to docs queue for hook files

sven.lauer’s picture

Status: Active » Fixed

This has actually been fixed by #574284: Documentation problem with hook_forms, I think.

Status: Fixed » Closed (fixed)
Issue tags: -API clean-up

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