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.
http://api.drupal.org/api/function/hook_menu
Browsing through the handbook pages on the new menu system, a fair number of keys seem to be missing from the API docs, which should be the authority.
http://drupal.org/node/300997 -- tab stuff, file stuff.
http://drupal.org/node/224170 -- load arguments
Comment | File | Size | Author |
---|---|---|---|
#42 | drupal.hook-menu-docs.42.patch | 12 KB | sun |
#35 | drupal.hook-menu-docs.patch | 10.21 KB | sun |
#34 | 382834.patch | 9.31 KB | jhodgdon |
#28 | 382834-hook-menu-review.patch | 8.81 KB | Pinolo |
#26 | 382834-hook-menu-again.patch | 8.82 KB | jhodgdon |
Comments
Comment #1
jhodgdonThe doc is also malformed (Return Value header is at the bottom of the page, after the text explaining what the form elements are, due to extra newline). I will patch both issues at once
Comment #2
jhodgdonComment #3
cwgordon7 CreditAttribution: cwgordon7 commentedComment #4
cwgordon7 CreditAttribution: cwgordon7 commentedHere's a patch.
Comment #6
boombatower CreditAttribution: boombatower commentedComment #7
jredding CreditAttribution: jredding commentedapplied against head and the documentation changes were made. Looks good
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedThis will need ported once it is applied to D7.
Comment #9
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD.
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #12
joachim CreditAttribution: joachim commentedIsn't there the stuff about tabs too?
Comment #13
sunEither use a comma, or start the next sentence with an uppercase letter.
"URL" is always uppercase.
Comment #14
cwgordon7 CreditAttribution: cwgordon7 commentedOops, nice catch, sun. The attached patch fixes the grammatical problems pointed out in #13, and also removes an extraneous period I noticed from the hook_menu() docs.
Comment #15
sunComment #16
jhodgdonThis looks like an excellent grammar, punctuation, and capitalization update to me.
However, the original patch (which was applied) and this patch as well didn't fix one of the problems in http://api.drupal.org/api/function/hook_menu/7, as noted in comment #1 above -- which is that there is a big section of bullet points that belongs in the Return Value section, but because of an extra newline, that section is not being picked up as part of the Return Value section (it's up in the main documentation). So, it would be good to add that to your patch.
Also, note that a port to 6.x is also needed, which would incorporate the changes from #4 and this current patch.
Comment #17
joachim CreditAttribution: joachim commentedWe're still missing:
'tab_parent' => NULL,
'tab_root' => NULL,
'block callback' => '',
and possibly others. I have no idea what the above do by the way. Is the author of the D6 menu system around?
Comment #18
cwgordon7 CreditAttribution: cwgordon7 commentedAs far as I understand, the tab_ stuff does internal tab-related stuff that's best not to mess with. I can add documentation ("this is used internally") for those if you'd like. As far as I understand again, block callback refers to the callback that returns the block on the administration page ("Content management" / "Site building" / etc.)
I believe the attached patch should fix the problem with blank lines.
Comment #19
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. I'm setting this to 'code needs work' so we can add the missing bits.
Comment #20
stella CreditAttribution: stella commentedActually the 'file' and 'file path' elements have been removed from hook_menu() in Drupal 7 (http://drupal.org/node/224333#menu_file_path)
Comment #21
jhodgdonI'll patch this...
Comment #22
jhodgdonI looked through the code, including system_install(), _menu_router_build(), and other functions that deal with the menu system.
There were several components missing, and several that had to be removed.
I also did some grammatical/style/clarity edits, since I can never resist those :), fixed an over-80-character line, and added a section to the hook_menu() doc that explains the magic auto-loading functionality (which I was amazed at when I discovered it once by delving into the code, and think should be there in the doc, because it is certainly not obvious until you find out about it).
Anyway, here's a patch of revisions to the hook_menu() documentation.
Comment #23
joachim CreditAttribution: joachim commentedVery nice!
The autoloading stuff was very definitely in need of writing up.
Some very minor points:
Can this be made into a magic @see link?
'path argument' make me think of what arg() gets -- the term 'load arguments' is used for this lower down, which is clearer.
This review is powered by Dreditor.
Comment #24
jhodgdonMaybe we don't even need a link to arg() there at all? I just reformatted what was there into 80-character line, but thinking more about it, I don't really see what a link to the arg() function does for the explanation. In any case, any time you put a function name in like arg() with the parens, the API display module turns it into a magic link.
Regarding your second comment, this is not the same as a load argument actually. Load arguments refers to making the load_foo() function take extra arguments. This refers to making $node substitute for 12345 if your page or access function asks for path component #2. But I agree maybe the current wording could be confusing... Not sure what the best wording is... any ideas?
Comment #25
jhodgdonWait, I have an idea. New patch coming...
Comment #26
jhodgdonHere it is...
Comment #27
jhodgdonThis time, I decided a paragraph at the top explaining the path component substitution also made sense.
Comment #28
PinoloI corrected a couple of repetitions.
+ * can also register a link to be placed in the the navigation block
+ * Your registered paths can contain also contain special
Also, throughout the text, I see several uses of "pass into", "pass to" and such, related to the act of sending data to functions/callbacks. As a non-native English speaker, my bet would be on "pass on to" as the correct form, but I leave this matter to natives.
Comment #30
webchickOh, testing bot...
Comment #32
sun.core CreditAttribution: sun.core commentedComment #34
jhodgdonThat above patch indeed would not apply, due to other changes...
Here is a new patch.
I'm assuming that the file/file path stuff needs to be there again, since the registry went away? At least, I see it in node_menu(), so I am assuming it should be left in the hook_menu() doc now.
Comment #35
sunRevamped. Code examples usually do better.
Comment #36
joachim CreditAttribution: joachim commentedI'll leave the bot to test how it applies, but I gave this a read-through.
Very good explanation of argument substitution! Learnt a few new things :)
Big improvement overall.
Just one tweak -- strange turn of phrase here:
+ * menu argument loader function, which would be mymodule_abc_load() then. For
Better this way:
+ * menu argument loader function, which here would be mymodule_abc_load(). For
Comment #37
jhodgdonAlso, what's this "again"? Awkward wording... I think maybe you are trying to say it is a nested array?
Anyway, I think the prose in your version needs some work... it's probably no surprise that I liked my prose explanations better. :)
Comment #38
Anonymous (not verified) CreditAttribution: Anonymous commentedIs the following better?
Comment #39
joachim CreditAttribution: joachim commented+1 to earnie's change.
Comment #40
jhodgdon[deleted]
Comment #41
jhodgdonJust a note: #583398: Not clear that access callbacks have to be in the same file as hook_menu.
Both my patch in #34 and sun's patch in #35 address this (making sure the file element says it doesn't apply to access callbacks). Any future versions should too.
Comment #42
sunThanks for the reviews + suggestions!
Incorporated those.
Furthermore, I realized that we explain all that advanced argument handling stuff, but not a single word about the most trivial case: optional default arguments. Revised nightmare attached.
Comment #43
jhodgdonThis is great.
Comment #44
sunTagging.
Comment #45
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!
Comment #46
jhodgdonShould we consider porting all/some of this patch to Drupal 6? I think it would be a good idea to have this explanation of auto-load and arg substitution there as well.
Comment #47
joachim CreditAttribution: joachim commentedYes, very good idea.
Which parts aren't relevant to D6?
Comment #48
jhodgdonCheck to make sure, but I think "theme callback" and args were added in D7. Maybe other components? "block callback"? "tab root"?
Also might be good to wait a day or two and incorporate
#536788: Provide documentation on making menu tabs
into the same D6 port, assuming it gets accepted/committed.
Comment #49
jhodgdonAfter a careful look through the D6 code, I believe that only these two items need to be omitted for D6:
theme callback
theme arguments
Comment #50
jhodgdonThat other issue #536788: Provide documentation on making menu tabs was committed to D7. So they can be ported to D6 together, if desired.
Comment #51
jhodgdonActually, I would wait on porting after all -- there is more discussion happening on that other issue... more changes to hook_menu doc happening... I am going to suggest that this patch NOT be ported, and we do the porting on the other issue instead.