Search code examples
drupalhook-menu

How to register a wildcard url in Drupal with the hook_menu?


I'm starting to work with Drupal and I'm really confused as how to create a hook_menu function that allows you to register a URL with 1 or 2 different values, that can be hidden and not displayed in the breadcrumbs.

Any help on this would be much appreciated. Even an example.


Solution

  • Not sure about the breadcrumbs bit, but I think you're looking for wildcard (%) and auto-loader wildcard (%mymodule_entity) components in the path.

    From the hook_menu() page...

    Wildcards within paths also work with integer substitution. For example, your module could register path 'my-module/%/edit'. When path 'my-module/foo/edit' is requested, integer 1 will be replaced with 'foo' and passed to the callback function. Note that wildcards may not be used as the first component.

    $items['my-module/%/edit'] = array(
      'page callback' => 'mymodule_abc_edit',
      'page arguments' => array(1),
    );
    

    Registered paths may also contain special "auto-loader" wildcard components in the form of '%mymodule_abc', where the '%' part means that this path component is a wildcard, and the 'mymodule_abc' part defines the prefix for a load function, which here would be named mymodule_abc_load().

    $items['my-module/%mymodule_abc/edit'] = array(
      'page callback' => 'mymodule_abc_edit',
      'page arguments' => array(1),
    );