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?
Comments
Comment #1
heine commentedYou are correct. The replacement regular expression follows http://www.php.net/functions
Comment #2
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 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 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 commentedCommitted to CVS HEAD. Thanks for the documentation.
Comment #8
gábor hojtsyNote that Dries also committed it to 6.x.
Comment #9
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 commentedhere's one possible fix:
Comment #11
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 commentedOups, here is a sane fix.
Comment #13
pwolanin commentedpatch against D6, applies w/ offset to D7.
Comment #14
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 commentedOh Damien's is a different! That's the good one. #12.
Comment #16
damien tournoud commentedFull test suite:
Comment #17
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 commentedComment #19
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) commentedAutomatically closed -- issue fixed for two weeks with no activity.