You are here

function menu_example_arg_optional_to_arg in Examples for Developers 6

Same name and namespace in other branches
  1. 7 menu_example/menu_example.module \menu_example_arg_optional_to_arg()

A to_arg() function is used to provide a default for the arg in the wildcard. The purpose is to provide a menu link that will function if no argument is given. For example, in the case of the menu item 'menu_example/default_arg/%menu_example_arg_optional' the third argument is required, and the menu system cannot make a menu link using this path since it contains a placeholder. However, when the to_arg() function is provided, the menu system will create a menu link pointing to the path which would be created with the to_arg() function filling in the %menu_example_arg_optional.

Parameters

$arg: The arg (URL fragment) to be tested.

Related topics

File

menu_example/menu_example.module, line 481
Demonstrates uses of the Menu APIs in Drupal, including hook_menu(), hook_menu_alter(), and hook_menu_link_alter().

Code

function menu_example_arg_optional_to_arg($arg) {

  // If our argument is not provided, give a default of 99.
  return empty($arg) || $arg == '%' ? 99 : $arg;
}