2

I have a function like:

function MYMODULE_menu() {
  $items['cars'] = array(
    'title' => 'Cars',
    'page callback' => 'section_index',
    'page arguments' => array("cars"),
    'access arguments' => array('access content'),
    'file' => 'pages/section.inc',
    'type' => MENU_CALLBACK,
  );
}

It works fine. Going to cars calls this page. I have a load of node pages like cars/ford and cars/volvo and they get called. However. If you go to cars/volvvvo (for example), it calls the "cars". No 404 is triggered etc.

This also seems to mean that the breadcrumb is glitchy for other pages called by hook_menu which have cars in the path, e.g.

 $items['cars/help'] = array(
    'title' => 'Cars Help',
    'page callback' => 'cars_help',
    'access arguments' => array('access content'),
    'file' => 'pages/help.inc',
    'type' => MENU_CALLBACK,
  );

Has a mangled breadcrumb with additional paths to "cars" in it.

Am I missing something? Is there a way to stop additional arguments being just silently pased through via hook_menu?

3

No, you can't, see the following question/answer: https://drupal.stackexchange.com/a/33493/31

If you only want to allow certain arguments, you need to validate the argument and return MENU_NOT_FOUND. Or you can use a named argument, e.g. cars/%brand, which will automatically call the brand_load() function, pass the value of the parameter to it and if that function returns FALSE, then it's automatically returned as 404. This is used for node/%node, user/%user and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.