When you set up a menu callback, if you enter the wildcard at first argument (to delegate authentication to a module for instance):
$items['%/authenticate'] = array(
'page callback' => 'oauth_delegate',
'page arguments' => array(0, 1),
'access callback' => 'oauth_implements',
'access arguments' => array(0),
'type' => MENU_CALLBACK,
'file' => 'oauth.inc',
);
/**
* Check if a module implementing oauth exists.
*/
function oauth_implements($module) {
return function_exists($module . '_oauth_info');
}
Then it doesn't work. The function leads to 404 Page not found and the menu router doesn't even visit the access callback.
To fix the problem i added a fixed first argument:
$items['oauth/%/authenticate'] = array(
'page callback' => 'oauth_delegate',
'page arguments' => array(1, 2),
'access callback' => 'oauth_implements',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
'file' => 'oauth.inc',
);
But for patterns like delegation, i.e. OAuth based authentication where module implements and instantiate the protocol, it is nice for a user perspective to have urls like:
"twitter/authenticate"
"facebook/authenticate"
"linkedin/authenticate"
Comment | File | Size | Author |
---|---|---|---|
#11 | menu-wildcards-1087940-11.patch | 716 bytes | drupal_was_my_past |
#3 | docs_1087940.patch | 738 bytes | drewish |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is by design.
Comment #2
Sylvain Lecoy CreditAttribution: Sylvain Lecoy commentedI probably missed something in the doc telling that we can't use a wildcard as first parameters.
Then it should be updated if not.
Comment #3
drewish CreditAttribution: drewish commentedIs this sufficient?
Comment #4
Sylvain Lecoy CreditAttribution: Sylvain Lecoy commentedYes it is :-)
Sorry when i rewrite my sentence it sounds a bit unmannered but it was not the purpose I just wrote it without re-reading after. Do you know if there is any plans to make the wildcard working as first component ? It has some use cases where it may be useful.
Comment #5
jhodgdonSylvain: it won't be changed in D7 -- you can file a feature request for d8 to ask for it there. The patch looks good to me, and should probably be applied to d7 and d8 at least for now.
Comment #6
jhodgdonNeeds to go to d8 and then d7
Comment #7
catchComment #8
webchickReading the rest of the docs at http://api.drupal.org/api/drupal/modules--system--system.api.php/functio..., I actually think this note probably would read better right after this sentence, where we show the first example about wildcards:
"When path 'my-module/foo/edit' is requested, integer 1 will be replaced with 'foo' and passed to the callback function."
What say you?
Comment #9
jhodgdonNo, actually this isn't about integer substitution, it's about wildcards in the path string, which is different. So it's in the right place.
To clarify this, I suggest the additional line be:
Note that wildcards may not be used as the first component in the path you are defining.
Comment #10
jhodgdonOoops, my mistake. Yes, up farther in that paragraph would be a better placement.
Comment #11
drupal_was_my_past CreditAttribution: drupal_was_my_past commentedRe-roll patch from #3 with @webchick's suggestion in #8.
Comment #12
jhodgdonLooks good, thanks!
Comment #13
chx CreditAttribution: chx commentedThe design was that % wouldnt work. file a feature req for %/authenticate. The docs patch is ok for now.
Comment #14
Dries CreditAttribution: Dries commentedCommitted to 7.x and 8.x. Thanks.