Implements hook_menu().
This implementation turns every subdirectory of this module into a category that is exposed as a menu link. Each subdirectory contains include files that consist of a callback function that maps to the semantics of the category. The following categories are supported:
For example, given an include file:
./page/list-operations.inc
A menu router item with the path 'design_test/page/list-operations' will be auto-generated. Upon access, the function design_test_page_list_operations() will be called.
The 'form' category behaves identically; e.g., for an include file './form/details.inc' a menu item for the path 'design_test/form/details' is created and the form constructor function design_test_form_details() will be called.
Each resulting test page is enhanced with local actions that allow to quickly switch between enabled themes for verifying the expected output.
function design_test_menu() {
// Turn each include file in the module directory into a local task.
$categories = array();
$module_path = drupal_get_path('module', 'design_test');
$tests = file_scan_directory($module_path, '/\\.inc$/', array(
'key' => 'name',
'recurse' => TRUE,
));
foreach ($tests as $name => $file) {
// Build include file path and category.
$filepath = strtr($file->uri, array(
$module_path . '/' => '',
));
list($category) = explode('/', $filepath, 2);
$categories[$category] = $category;
// Build router item path.
$path = preg_replace('@[^a-zA-Z0-9-]@', '-', $name);
// Build page callback function name.
$callback = "design_test_{$category}_" . strtr($path, '-', '_');
// Build router item callback.
if ($category == 'form') {
$page_callback = 'drupal_get_form';
}
else {
$page_callback = $callback;
}
$items["design_test/{$category}/{$path}"] = array(
'title' => drupal_ucfirst($name),
'theme callback' => 'design_test_menu_theme_callback',
'page callback' => $page_callback,
'page arguments' => array(
$callback,
),
'file' => $filepath,
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK | MENU_VISIBLE_IN_TREE,
);
}
$items['design_test'] = array(
'title' => 'Design test',
'page callback' => 'design_test_category_page',
'page arguments' => array(
1,
),
'access callback' => TRUE,
);
$items['design_test/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
// Lastly, add the category containers.
foreach ($categories as $category) {
$items["design_test/{$category}"] = array(
'title' => drupal_ucfirst($category),
'page callback' => 'design_test_category_page',
'page arguments' => array(
1,
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK | MENU_VISIBLE_IN_TREE,
);
}
return $items;
}