I am trying to define my own wildcard loader function and noticed that if I use a number as part of the wildcard loader name then it does not get called.
This below doesn't work. My function s3_object_load() does not get called, and nor does s3_object_page(). I end up with a 'page not found':
// in hook_menu:
$items['amazon/%s3_object/view'] = array(
'title' => 'View S3 object',
'page callback' => 's3_object_page',
'page arguments' => array(1),
'access callback' => 'user_access',
'access arguments' => array('administer s3'),
);
}
// end of hook_menu snippet
// Loader function I want to use, but never gets called
function s3_object_load() {
}
The code below does work (the loader function gets called, and so does s3_object_page()):
// in hook_menu:
$items['amazon/%s_three_object/view'] = array(
'title' => 'View S3 object',
'page callback' => 's3_object_page',
'page arguments' => array(1),
'access callback' => 'user_access',
'access arguments' => array('administer s3'),
);
}
// end of hook_menu snippet
// Loader function that works
function s_three_object_load() {
}
Note that the only change made was renaming the loader function from 's3_object' to 's_three_object'. I suspect there is a problem somewhere in the path parsing caused by the inclusion of digits in loader function names.
Any ideas?
Comment | File | Size | Author |
---|---|---|---|
#13 | empty-or-valid-callback-285165-11.patch | 923 bytes | pwolanin |
#12 | 285165-wildcard-fix.patch | 879 bytes | Damien Tournoud |
#6 | menu-inc-wildcard-loader-pattern.patch | 966 bytes | Gábor Hojtsy |
#1 | menu_object_loader.patch | 735 bytes | Heine |
Comments
Comment #1
Heine CreditAttribution: Heine commentedYou are correct. The replacement regular expression follows http://www.php.net/functions
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedLooks quite reasonable, but should go to 7.x first. The same patch should apply to 7.x (Heine, can you confirm?).
This is quite a small fix, so submitting "as is" for Dries review.
Comment #3
lilou CreditAttribution: lilou commentedPatch applied successfully to CVS HEAD.
Comment #4
webchickHa, that's a fun bug.
Can we please have a comment or two to explain what the hell that scary regex does? :)
Comment #5
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe comment should cite http://php.net/manual/en/language.functions.php, which document that regexp.
Comment #6
Gábor HojtsyMy issue on #321040: QUICKFIX: menu system does not allow numbers and uppercase in wildcard names was marked as a clear duplicate of this one. So let's get this fixed :) The attached patch includes comments and works for me with wildcards such as %l10n_community_language and %l10n_community_project.
Comment #7
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks for the documentation.
Comment #8
Gábor HojtsyNote that Dries also committed it to 6.x.
Comment #9
pwolanin CreditAttribution: pwolanin commentedthis regex is wrong - it just broke a large fraction of all existing menu paths
that only matches if the % is followed by at least one char
Comment #10
pwolanin CreditAttribution: pwolanin commentedhere's one possible fix:
Comment #11
chx CreditAttribution: chx commented%([a-zA-Z_][a-zA-Z_0-9]*)?
do not overcomplicate. this plus _load is a PHP identifier. Starts with a letter or an underscore, continues the same plus numbers.Comment #12
Damien Tournoud CreditAttribution: Damien Tournoud commentedOups, here is a sane fix.
Comment #13
pwolanin CreditAttribution: pwolanin commentedpatch against D6, applies w/ offset to D7.
Comment #14
chx CreditAttribution: chx commentedWhy so complicated, sweet heavens. %$ is not needed, it's going to cause you notice issue. Use the ^%([whatever][whatever0-9]*)?$ notation.
Comment #15
chx CreditAttribution: chx commentedOh Damien's is a different! That's the good one. #12.
Comment #16
Damien Tournoud CreditAttribution: Damien Tournoud commentedFull test suite:
Comment #17
pwolanin CreditAttribution: pwolanin commentedby way of explanation, chx liked Damien's better since $matches[1] will be set still (though empty) for a plain %
Comment #18
pwolanin CreditAttribution: pwolanin commentedComment #19
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!
Comment #20
Gábor HojtsySince Dries did not commit the followup in #12 to Drupal 6 this time, I did. So this is also closed for Drupal 6.
Comment #21
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.