Marking critical because it's missing hook documentation.
If you don't read form.inc on a regular basis, you might be unaware that in addition to hook_form_alter(), which fires for any form in the system, there is also a more granular hook_form_FORM_ID_alter() (for example, custom_form_user_register_alter() for the registration form.
This is a nice little feature and we need docs for it in contributions/docs/developers/hooks/core.php. Anyone with contrib CVS access (i.e. anyone who can maintain a module, theme, translation, etc.) can update these docs. The changes need to be made to HEAD and DRUPAL-6.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | formapi.patch | 1.21 KB | jhodgdon |
| #30 | formapi.patch | 888 bytes | jhodgdon |
| #28 | formapi.patch | 769 bytes | jhodgdon |
| #18 | 331832-6.x.patch.txt | 757 bytes | jhodgdon |
| #17 | 331832.patch | 768 bytes | jhodgdon |
Comments
Comment #1
amitaibuWhat do you think of this (with the use of http://drupal.org/node/144132#form-id-alter):
Comment #2
cburschkaWow, I didn't know this. Well, I had heard of it at some point, but I've never made use of it even though it would have been very useful.
Is there a specific reason that the forms in your example are named with Greek letters (as opposed to numbers or Latin letters), or that the second form is named "zeta" instead of, say, "beta"?
Also, I'm not sure the hook needs to be implemented three times - after the first "hook_form_my_form_alter" developers might get the point...
Edit: I see that the three implementations are a legacy of the 5.x->6.x upgrading page, but I really think they're only necessary to explain that change, not to document the function itself.
Comment #3
amitaibuComment #4
dmitrig01 commentedLooks good
Comment #5
webchickGreat job! Some comments:
a) Let's make just one function and call it literally "hook_form_FORM_ID_alter". This is so that when people make implementations of this hook, and go "Implementation of hook_form_FORM_ID_alter()." it will properly map over to the API documentation. The FORM_ID matches with our template preprocess hooks (see http://api.drupal.org/api/function/theme).
b) That means the reference in the comment needs to be fixed too.
c) Please remove the newline between the end of the PHPDoc and the function definition; this will case api.drupal.org to not parse the docs correctly (annoying, but true! :)).
d) I'd like to suggest something a bit more "real" as the example code, to give people a better idea of why they might use this. I know terms_of_use.module uses one of these to add terms to the registration form, so a simpler example of that might be good.
How about something like:
Comment #6
cburschkaChanges are below.
Further comments:
- The stuff about call order is contradictory. First we state that this is called /before/ the general hook_form_alter, then we state that the hook_form_alter of module beta will be triggered before the hook_form_FORM_ID_alter of alpha. I've tried to resolve that below, please check if it is still accurate.
- Consider consistently calling it hook_form_FORM_ID_alter instead of hook_form_$form-id_alter...
Comment #7
webchickRight, that's what I meant by b) :) So anywhere it says hook_form_$form-id_alter it should be hook_form_FORM_ID_alter.
How about "rather than a global hook_form_alter()" or something that implies that hook_form_alter() applies to *all* forms, and this one to only a specific one.
Other than that looks great! Feel free to commit this once these small changes are in! :)
Comment #8
cburschkaLol, I thought that was your job. I keep forgetting that the docs repository is open for everybody. ;)
Well, here's my final version. I also took out some of the text that seemed specific to updating instructions - nobody needs to know that a hook is "optional".
Looks as if this can go in!
Comment #9
cburschkaHere's a patch for core.php. I put the function right after hook_form_alter.
Comment #10
webchickLooks great!
Please commit to both HEAD and DRUPAL-6--1. :)
Comment #11
cburschkaThis I have done. :)
Comment #12
webchickYay!! You guys rock!! Thanks, Arancaytar and Amitaibu! :)
Comment #14
miro_dietikerHey that's pretty cool! But...
I'd suggest adding this to the hook_form_alter page too:
http://api.drupal.org/api/function/hook_form_alter
For people to understand there's an alternative (better) way.
Comment #15
joachim commented+1 to #14 -- add a mention and a link.
Comment #16
jhodgdonComment #17
jhodgdonComment #18
jhodgdonComment #19
jhodgdonAbove are patches for 7.x and 6.x for #14
Comment #20
webchickLooks great! Committed to HEAD. Feel free to commit to the 6.x docs, anyone with contributions access. :)
Comment #21
jhodgdonI don't have contrib access (yet, and/or haven't applied yet). Someone else?
Comment #22
gábor hojtsyCommitted to the contrib hook docs in 6.x: http://drupal.org/cvs?commit=190462
Comment #24
joachim commentedReopening:
+ * Note that you can also use hook_FORM_ID_alter() to alter a specific form,
It's hook_form_FORM_ID_alter()
Comment #25
webchickD'oh. :P
Comment #26
jhodgdonWhoops. I put hook_FORM_ID_alter() rather than hook_form_FORM_ID_alter() in my earlier patches, and no one else noticed the error either, so those lines got committed with the wrong hook name in them. So someone needs to make a new patch (against the current D6 and D7 documentation) to fix this error.
I don't have time to do it today, so if someone else wants to take it on to get their feet wet with supplying patches (webchick marked it as "Novice" for that reason), that is fine. Otherwise, I'll try and get to it sometime soon.
Comment #27
dave reidI fixed the 6.x documentation, now we just need to patch system.api.php in D7.
Comment #28
jhodgdon6.x looks good to me. Here's a patch for 7.x
Comment #29
dave reidLet's make sure that line gets wrapped at 80 characters (move the last word to the next line).
Comment #30
jhodgdonGood idea. How about this patch?
Comment #31
dave reidAnother minor nitpick (sorry!), can we remove this extra comma?
"Note that you can also use hook_form_FORM_ID_alter() to alter a specific form, instead of this hook,"
So that it is :
"Note that you can also use hook_form_FORM_ID_alter() to alter a specific form instead of this hook,"
Comment #32
jhodgdonCan we get a second opinion on that comma? I think the comma is necessary, because the "instead of this hook" clause refers to the beginning of the sentence (using a different hook) rather than what is just before it (alter a form).
Comment #33
keith.smith commentedOoh! Commas.
If a sentence can be made more clear with commas, then by all means use them. However, in this case, why don't we just rearrange this sentence so that the entire thing is more clear.
This is what I understand it to be saying:
Comment #34
joachim commented+1 to #33.
Comment #35
webchickSounds good to me, too. :)
Thanks a lot for your attention to detail, folks!
Comment #36
jhodgdonComment #37
jhodgdonOK, here's one more go at it. :)
I also removed the @return: None. section.
If this is OK, I can also patch D6 (I have contrib CVS access now).
Comment #38
jhodgdonComment #39
webchickAwesome. Committed to HEAD! Thanks a lot, jhodgdon!
The one tiny thing I did before I committed was remove the single trailing space at the end of the "Note that instead of hook_form_alter(), which is called for all forms, you" line.
Marking down to 6 so that the same fix is committed there. Thanks!
Comment #40
jhodgdonGracious. Forgot one. :)
I'll assign this back to myself and patch D6 in the next day or two. I do have contrib repos access now.
Comment #41
jhodgdonI went ahead and committed the same wording change as the patch in #37 (with the end of line fix) to D6 docs: http://drupal.org/cvs?commit=204464
Hope that's OK. I figured it has now probably been reviewed to death.
Comment #42
webchickyep, that's totally cool. :) Thanks so much, jhodgdon!!