API page: http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
Describe the problem you have found:
If you pass an integer in 'access arguments' (and the other callbacks), it is interpreted as an index into the path. If you want to pass an actual integer to the function, you need to make it be a string, such as '2' instead of the integer 2.
This is not documented in hook_menu() in the section that talks about path substitution, and it should be.
davereid points out on IRC that it *is* documented here: http://drupal.org/node/109153#integers
So this should be adapted and put into the hook_menu doc for d8/7 and maybe even d6. Might be a good project for a Novice doc contributor?
Comment | File | Size | Author |
---|---|---|---|
#8 | hook_menu_doc_integer-1168686-8.patch | 1.04 KB | barbi |
#4 | hook_menu_doc_integer-1168686.patch | 903 bytes | barbi |
Comments
Comment #1
Dave ReidI think we just need to add a small clarification to this part:
Proposed:
Comment #2
barbi CreditAttribution: barbi commentedsubscribe
Comment #3
jhodgdonLooks pretty good. Slight changes to the added text from #1:
To pass an integer without it being replaced with its respective path component, use the string value of the integer (e.g., '1') as the argument value.
[replace -> replaced, and comma after e.g.]
Comment #4
barbi CreditAttribution: barbi commentedComment #5
jhodgdonThanks! D7/8 please... then we should probably mark "patch/to be ported" for D6.
Comment #6
webchickHm. The text reads to me as though there's about to follow an example of passing in an argument as a string, but that's not what follows:
Should we expand the example to also include a literal '1'? Or slightly re-write the text so that the association is not so close?
Comment #7
jhodgdonAgreed. How about if we move the additional sentence up by one sentence? So it would read:
That is, the integer 0 in an argument list will be replaced with the first path component, integer 1 with the second, and so on (path components are numbered starting from zero). To pass an integer without it being replaced with its respective path component, use the string value of the integer (e.g., '1') as the argument value. This substitution feature allows you to re-use a callback function for several different paths. For example: [example follows]
Comment #8
barbi CreditAttribution: barbi commentedRearranged the sentence order and recreated the patch.
Comment #9
joachim CreditAttribution: joachim commentedLooks good to me.
Comment #10
jhodgdonme too.
This is for 8.x/7.x by the way. Then we should probably mark "patch/to be ported" for D6.
Comment #11
webchickPerfect!
Committed to 8.x and 7.x. Thanks!
Comment #12
webchickOops.
Comment #13
drupal_was_my_past CreditAttribution: drupal_was_my_past commentedLooks like D6 for this issue was fixed in #617424: Error in hook_menu documentation for load arguments.