summaryrefslogtreecommitdiff
path: root/includes/menu.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-02-28 16:23:27 +0000
committerDries Buytaert <dries@buytaert.net>2005-02-28 16:23:27 +0000
commit2b6d4c566e09c2006b84d21f22834d5f7c43bfe7 (patch)
tree1e8b685482869cb3266b5133a9839eacdc205c57 /includes/menu.inc
parent5f5f0b27aceedd0212a7375c4b7a97a6d0713a06 (diff)
downloadbrdo-2b6d4c566e09c2006b84d21f22834d5f7c43bfe7.tar.gz
brdo-2b6d4c566e09c2006b84d21f22834d5f7c43bfe7.tar.bz2
- Patch #17869: make local tasks more themeable.
Diffstat (limited to 'includes/menu.inc')
-rw-r--r--includes/menu.inc115
1 files changed, 87 insertions, 28 deletions
diff --git a/includes/menu.inc b/includes/menu.inc
index cfee5b6cd..d9eac0b5d 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -468,7 +468,7 @@ function menu_get_active_breadcrumb() {
$trail = _menu_get_active_trail();
foreach ($trail as $mid) {
if ($menu['items'][$mid]['type'] & MENU_VISIBLE_IN_BREADCRUMB) {
- $links[] = theme('menu_item', $mid);
+ $links[] = menu_item_link($mid);
}
}
@@ -545,28 +545,32 @@ function menu_rebuild() {
}
/**
- * Returns a rendered menu tree.
+ * Generate the HTML for a menu tree.
+ *
+ * @param $pid
+ * The parent id of the menu.
*
* @ingroup themeable
*/
-function theme_menu_tree($pid = 1, $all = FALSE) {
+function theme_menu_tree($pid = 1) {
+ if ($tree = menu_tree($pid)) {
+ return "\n<ul>\n". $tree ."\n</ul>\n";
+ }
+}
+
+/**
+ * Returns a rendered menu tree.
+ *
+ * @param $pid
+ * The parent id of the menu.
+ */
+function menu_tree($pid = 1) {
$menu = menu_get_menu();
$output = '';
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
-
foreach ($menu['visible'][$pid]['children'] as $mid) {
- $style = (count($menu['visible'][$mid]['children']) ? ((menu_in_active_trail($mid) || ($menu['visible'][$mid]['type'] & MENU_EXPANDED)) ? 'expanded' : 'collapsed') : 'leaf');
- $output .= "<li class=\"$style\">";
- $output .= theme('menu_item', $mid);
- if ($all || menu_in_active_trail($mid) || ($menu['visible'][$mid]['type'] & MENU_EXPANDED)) {
- $output .= theme('menu_tree', $mid);
- }
- $output .= "</li>\n";
- }
-
- if ($output != '') {
- $output = "\n<ul>\n$output\n</ul>\n";
+ $output .= theme('menu_item', $mid, menu_in_active_trail($mid) || ($menu['visible'][$mid]['type'] & MENU_EXPANDED) ? theme('menu_tree', $mid) : '', count($menu['visible'][$mid]['children']) == 0);
}
}
@@ -574,14 +578,42 @@ function theme_menu_tree($pid = 1, $all = FALSE) {
}
/**
- * Generate the HTML representing a given menu item ID.
+ * Generate the HTML output for a single menu item.
*
* @param $mid
- * The menu ID to render.
+ * The menu id of the item.
+ * @param $children
+ * A string containing any rendered child items of this menu.
+ * @param $leaf
+ * A boolean indicating whether this menu item is a leaf.
+ *
+ * @ingroup themeable
+ */
+function theme_menu_item($mid, $children = '', $leaf = TRUE) {
+ return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. menu_item_link($mid) . $children ."</li>\n";
+}
+
+/**
+ * Generate the HTML representing a given menu item ID.
+ *
+ * @param $item
+ * The menu item to render.
+ * @param $link_mid
+ * The menu item which should be used to find the correct path.
*
* @ingroup themeable
*/
-function theme_menu_item($mid) {
+function theme_menu_item_link($item, $link_item) {
+ return l($item['title'], $link_item['path'], array_key_exists('description', $item) ? array('title' => $items['description']) : array());
+}
+
+/**
+ * Returns the rendered link to a menu item.
+ *
+ * @param $mid
+ * The menu item id to render.
+ */
+function menu_item_link($mid) {
$menu = menu_get_menu();
$link_mid = $mid;
@@ -589,7 +621,7 @@ function theme_menu_item($mid) {
$link_mid = $menu['items'][$link_mid]['pid'];
}
- return l($menu['items'][$mid]['title'], $menu['items'][$link_mid]['path'], array_key_exists('description', $menu['items'][$mid]) ? array("title" => $menu['items'][$mid]['description']) : array());
+ return theme('menu_item_link', $menu['items'][$mid], $menu['items'][$link_mid]);
}
/**
@@ -599,24 +631,49 @@ function theme_menu_item($mid) {
* @ingroup themeable
*/
function theme_menu_local_tasks() {
+ $output = '';
+
+ if ($primary = menu_primary_local_tasks()) {
+ $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
+ }
+ if ($secondary = menu_secondary_local_tasks()) {
+ $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
+ }
+
+ return $output;
+}
+
+/**
+ * Returns the rendered HTML of the primary local tasks.
+ */
+function menu_primary_local_tasks() {
$local_tasks = menu_get_local_tasks();
$pid = menu_get_active_nontask_item();
$output = '';
if (count($local_tasks[$pid]['children'])) {
- $output .= "<ul class=\"tabs primary\">\n";
foreach ($local_tasks[$pid]['children'] as $mid) {
- $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid));
+ $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid), TRUE);
}
- $output .= "</ul>\n";
+ }
+
+ return $output;
+}
+
+/**
+ * Returns the rendered HTML of the secondary local tasks.
+ */
+function menu_secondary_local_tasks() {
+ $local_tasks = menu_get_local_tasks();
+ $pid = menu_get_active_nontask_item();
+ $output = '';
+ if (count($local_tasks[$pid]['children'])) {
foreach ($local_tasks[$pid]['children'] as $mid) {
if (menu_in_active_trail($mid) && count($local_tasks[$mid]['children']) > 1) {
- $output .= "<ul class=\"tabs secondary\">\n";
foreach ($local_tasks[$mid]['children'] as $cid) {
- $output .= theme('menu_local_task', $cid, menu_in_active_trail($cid));
+ $output .= theme('menu_local_task', $cid, menu_in_active_trail($cid), FALSE);
}
- $output .= "</ul>\n";
}
}
}
@@ -631,15 +688,17 @@ function theme_menu_local_tasks() {
* The menu ID to render.
* @param $active
* Whether this tab or a subtab is the active menu item.
+ * @param $primary
+ * Whether this tab is a primary tab or a subtab.
*
* @ingroup themeable
*/
-function theme_menu_local_task($mid, $active) {
+function theme_menu_local_task($mid, $active, $primary) {
if ($active) {
- return '<li class="active">'. theme('menu_item', $mid) ."</li>\n";
+ return '<li class="active">'. menu_item_link($mid) ."</li>\n";
}
else {
- return '<li>'. theme('menu_item', $mid) ."</li>\n";
+ return '<li>'. menu_item_link($mid) ."</li>\n";
}
}