<?php
function design_test_menu() {
$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) {
$filepath = strtr($file->uri, array(
$module_path . '/' => '',
));
list($category) = explode('/', $filepath, 2);
$categories[$category] = $category;
$path = preg_replace('@[^a-zA-Z0-9-]@', '-', $name);
$callback = "design_test_{$category}_" . strtr($path, '-', '_');
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,
);
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;
}
function design_test_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($router_item['number_parts'] > 2 && strpos($root_path, 'design_test/') === 0) {
$actions =& $data['actions']['output'];
$selected_theme = drupal_container()
->get('request')->query
->get('theme');
$default_theme = variable_get('theme_default', 'stark');
$themes = list_themes();
foreach ($themes as $name => $theme) {
$action = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => $theme->info['name'],
'href' => $router_item['href'],
'localized_options' => array(
'html' => FALSE,
),
),
'#active' => $selected_theme == $name,
);
if ($name != $default_theme) {
$action['#link']['localized_options']['query']['theme'] = $name;
}
$actions[] = $action;
}
if ($themes > 1) {
$data['actions']['count']++;
}
}
}
function design_test_menu_theme_callback() {
return drupal_container()
->get('request')->query
->get('theme');
}
function design_test_category_page($category) {
$link = menu_link_get_preferred();
$tree = menu_build_tree($link['menu_name'], array(
'expanded' => array(
$link['mlid'],
),
'min_depth' => $link['depth'] + 1,
'max_depth' => $link['depth'] + 2,
));
foreach ($tree as &$data) {
if (!($data['link']['type'] & MENU_LINKS_TO_PARENT)) {
$data['link']['hidden'] = 0;
}
}
$build = menu_tree_output($tree);
return $build;
}