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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Assigned: Unassigned » jhodgdon

The 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

jhodgdon’s picture

Assigned: jhodgdon » Unassigned
cwgordon7’s picture

Version: 6.x-dev » 7.x-dev
Assigned: Unassigned » cwgordon7
cwgordon7’s picture

Status: Active » Needs review
FileSize
1.83 KB

Here's a patch.

Status: Needs review » Needs work

The last submitted patch failed testing.

boombatower’s picture

Status: Needs work » Needs review
jredding’s picture

Status: Needs review » Reviewed & tested by the community

applied against head and the documentation changes were made. Looks good

Anonymous’s picture

This will need ported once it is applied to D7.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD.

Anonymous’s picture

Status: Fixed » Patch (to be ported)
Anonymous’s picture

Version: 7.x-dev » 6.x-dev
joachim’s picture

Isn't there the stuff about tabs too?

sun’s picture

Version: 6.x-dev » 7.x-dev
Status: Patch (to be ported) » Needs work
+ *   - "file": A file that will be included before the callbacks are accessed.
+ *     this allows callback functions to be in separate files. The file should

Either use a comma, or start the next sentence with an uppercase letter.

+ *     the arguments corresponding to the second and fourth url argument;
+ *     as with other arguments, integers are automatically cast to url
...
+ *     to the url index where the object's load function is specified; "%map"

"URL" is always uppercase.

cwgordon7’s picture

Oops, 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.

sun’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Status: Needs review » Needs work

This 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.

joachim’s picture

We'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?

cwgordon7’s picture

Status: Needs work » Needs review
FileSize
3.04 KB

As 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.

Dries’s picture

Status: Needs review » Needs work

Committed to CVS HEAD. I'm setting this to 'code needs work' so we can add the missing bits.

stella’s picture

Actually the 'file' and 'file path' elements have been removed from hook_menu() in Drupal 7 (http://drupal.org/node/224333#menu_file_path)

jhodgdon’s picture

Assigned: cwgordon7 » jhodgdon

I'll patch this...

jhodgdon’s picture

Assigned: jhodgdon » Unassigned
Status: Needs work » Needs review
FileSize
5.97 KB

I 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.

joachim’s picture

Very nice!
The autoloading stuff was very definitely in need of writing up.

Some very minor points:

+++ modules/menu/menu.api.php	13 Aug 2009 20:00:00 -0000
@@ -34,24 +48,19 @@
+ *     function. Integer values pass the corresponding URL component (see
+ *     arg()).

Can this be made into a magic @see link?

+++ modules/menu/menu.api.php	13 Aug 2009 20:00:00 -0000
@@ -14,19 +14,33 @@
+ * node_load(12345) will automatically be called, and this node object
+ * will be available as path argument 1 to the page and access

'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.

jhodgdon’s picture

Maybe 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?

jhodgdon’s picture

Wait, I have an idea. New patch coming...

jhodgdon’s picture

Here it is...

jhodgdon’s picture

This time, I decided a paragraph at the top explaining the path component substitution also made sense.

Pinolo’s picture

I 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.

Status: Needs review » Needs work

The last submitted patch failed testing.

webchick’s picture

Status: Needs work » Needs review

Oh, testing bot...

Status: Needs review » Needs work

The last submitted patch failed testing.

sun.core’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
9.31 KB

That 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.

sun’s picture

FileSize
10.21 KB

Revamped. Code examples usually do better.

joachim’s picture

I'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

jhodgdon’s picture

Status: Needs review » Needs work

Also, what's this "again"? Awkward wording... I think maybe you are trying to say it is a nested array?

+ * hook_menu() implementations return an associative array that contains again
+ * an associative array for each path. The definition for each path may refer to

Anyway, I think the prose in your version needs some work... it's probably no surprise that I liked my prose explanations better. :)

Anonymous’s picture

Is the following better?

 * hook_menu() implementations return an associative array whose keys
 * are the paths and whose element values are an associative array defining 
 * the path elements. ...
joachim’s picture

+1 to earnie's change.

jhodgdon’s picture

[deleted]

jhodgdon’s picture

Just 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.

sun’s picture

Status: Needs work » Needs review
FileSize
12 KB

Thanks 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.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

This is great.

sun’s picture

Issue tags: +API clean-up

Tagging.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

jhodgdon’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

Should 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.

joachim’s picture

Yes, very good idea.
Which parts aren't relevant to D6?

jhodgdon’s picture

Check 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.

jhodgdon’s picture

After a careful look through the D6 code, I believe that only these two items need to be omitted for D6:
theme callback
theme arguments

jhodgdon’s picture

That other issue #536788: Provide documentation on making menu tabs was committed to D7. So they can be ported to D6 together, if desired.

jhodgdon’s picture

Version: 6.x-dev » 7.x-dev
Status: Patch (to be ported) » Fixed

Actually, 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.

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

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