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:


#11 menu-wildcards-1087940-11.patch716 bytesdrupal_was_my_past
PASSED: [[SimpleTest]]: [MySQL] 34,012 pass(es). View
#3 docs_1087940.patch738 bytesdrewish
PASSED: [[SimpleTest]]: [MySQL] 31,535 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


Damien Tournoud’s picture

Status: Active » Closed (works as designed)

This is by design.

Sylvain Lecoy’s picture

Component: menu system » documentation
Status: Closed (works as designed) » Active

I probably missed something in the doc telling that we can't use a wildcard as first parameters.

Then it should be updated if not.

drewish’s picture

Version: 7.x-dev » 8.x-dev
Status: Active » Needs review
738 bytes
PASSED: [[SimpleTest]]: [MySQL] 31,535 pass(es). View

Is this sufficient?

Sylvain Lecoy’s picture

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

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Priority: Major » Normal
Status: Needs review » Reviewed & tested by the community

Sylvain: 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.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev

Needs to go to d8 and then d7

catch’s picture

Title: Wildcard % doesn't work as first argument in menu paths » Document that wildcard % doesn't work as first argument in menu paths
Issue tags: +needs backport to D7
webchick’s picture

Status: Reviewed & tested by the community » Needs review

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

jhodgdon’s picture

Status: Needs review » Needs work

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

jhodgdon’s picture

Ooops, my mistake. Yes, up farther in that paragraph would be a better placement.

drupal_was_my_past’s picture

Assigned: Unassigned » drupal_was_my_past
Status: Needs work » Needs review
716 bytes
PASSED: [[SimpleTest]]: [MySQL] 34,012 pass(es). View

Re-roll patch from #3 with @webchick's suggestion in #8.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

chx’s picture

The design was that % wouldnt work. file a feature req for %/authenticate. The docs patch is ok for now.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -needs backport to D7

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