summaryrefslogtreecommitdiff
path: root/modules/menu/menu.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/menu/menu.module')
-rw-r--r--modules/menu/menu.module140
1 files changed, 80 insertions, 60 deletions
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index 1f94e3b4b..8be50f4c0 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -2,19 +2,45 @@
// $Id$
/**
- * Implementation of hook_link().
+ * Implementation of hook_menu().
*/
-function menu_link($type, $node = 0, $main) {
- if ($type == 'system') {
- menu('admin/menu', t('menus'), user_access('administer menu') ? 'menu_overview' : MENU_DENIED, 0, MENU_SHOW);
- menu('admin/menu/reset', t('reset all menus'), user_access('administer menu') ? 'menu_reset' : MENU_DENIED, 0, MENU_SHOW);
- menu('admin/menu/menu/add', t('add menu'), user_access('administer menu') ? 'menu_add_menu' : MENU_DENIED, 0, MENU_SHOW);
- menu('admin/menu/item/add', t('add menu item'), user_access('administer menu') ? 'menu_edit_item' : MENU_DENIED, 0, MENU_SHOW);
- menu('admin/menu/item/edit', t('edit menu item'), user_access('administer menu') ? 'menu_edit_item' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
- menu('admin/menu/item/reset', t('reset menu item'), user_access('administer menu') ? 'menu_reset_item' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
- menu('admin/menu/item/disable', t('disable menu item'), user_access('administer menu') ? 'menu_disable_item' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
- menu('admin/menu/item/delete', t('delete menu item'), user_access('administer menu') ? 'menu_delete_item' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
- }
+function menu_menu() {
+ $items = array();
+ $items[] = array('path' => 'admin/menu', 'title' => t('menus'),
+ 'callback' => 'menu_overview',
+ 'access' => user_access('administer menu'));
+ $items[] = array('path' => 'admin/menu/item/edit', 'title' => t('edit menu item'),
+ 'callback' => 'menu_edit_item',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_CALLBACK);
+ $items[] = array('path' => 'admin/menu/item/reset', 'title' => t('reset menu item'),
+ 'callback' => 'menu_reset_item',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_CALLBACK);
+ $items[] = array('path' => 'admin/menu/item/disable', 'title' => t('disable menu item'),
+ 'callback' => 'menu_disable_item',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_CALLBACK);
+ $items[] = array('path' => 'admin/menu/item/delete', 'title' => t('delete menu item'),
+ 'callback' => 'menu_delete_item',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_CALLBACK);
+
+ // Tabs:
+ $items[] = array('path' => 'admin/menu/menu/add', 'title' => t('add menu'),
+ 'callback' => 'menu_add_menu',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array('path' => 'admin/menu/item/add', 'title' => t('add menu item'),
+ 'callback' => 'menu_edit_item',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array('path' => 'admin/menu/reset', 'title' => t('reset menus'),
+ 'callback' => 'menu_reset',
+ 'access' => user_access('administer menu'),
+ 'type' => MENU_LOCAL_TASK);
+
+ return $items;
}
/**
@@ -22,12 +48,12 @@ function menu_link($type, $node = 0, $main) {
*/
function menu_help($section) {
switch ($section) {
- case 'admin/system/modules#description':
+ case 'admin/modules#description':
return t('Allows administrators to customize the site navigation menu.');
case 'admin/menu':
return t('Select an operation from the list to move, change, or delete a menu item. To add a new menu, add a new menu item, or reset all menu items to default values, choose an option from the main menu.');
case 'admin/menu/menu/add':
- return t('Enter the name for your new menu. Remember to enable the newly created block in the %blocks administration page.', array('%blocks' => l(t('blocks'), 'admin/system/block')));
+ return t('Enter the name for your new menu. Remember to enable the newly created block in the %blocks administration page.', array('%blocks' => l(t('blocks'), 'admin/block')));
}
}
@@ -49,7 +75,7 @@ function menu_block($op = 'list', $delta = 0) {
}
else {
$data['subject'] = $menu['items'][$delta]['title'];
- $data['content'] = menu_tree($delta);
+ $data['content'] = theme('menu_tree', $delta);
return $data;
}
}
@@ -107,7 +133,7 @@ function menu_add_menu() {
break;
default:
$edit['pid'] = 0;
- $edit['status'] = MENU_CUSTOM;
+ $edit['type'] = MENU_CUSTOM_ITEM;
$output .= menu_edit_item_form($edit);
}
@@ -162,7 +188,11 @@ function menu_delete_item($mid) {
* Menu callback; hide a menu item.
*/
function menu_disable_item($mid) {
- db_query('UPDATE {menu} SET visibility = %d, status = %d WHERE mid = %d', MENU_HIDE, MENU_MODIFIED, $mid);
+ $menu = menu_get_menu();
+ $type = $menu['items'][$mid]['type'];
+ $type &= ~MENU_VISIBLE_IN_TREE;
+ $type &= ~MENU_VISIBLE_IN_BREADCRUMB;
+ db_query('UPDATE {menu} SET type = %d WHERE mid = %d', $type, $mid);
menu_rebuild();
drupal_set_message(t('menu item disabled.'));
print theme('page', menu_overview_tree());
@@ -174,6 +204,7 @@ function menu_disable_item($mid) {
function menu_edit_item($mid = 0) {
$op = $_POST['op'];
$edit = $_POST['edit'];
+
$output = '';
switch ($op) {
@@ -194,13 +225,12 @@ function menu_edit_item($mid = 0) {
$edit['path'] = $item->path;
$edit['title'] = $item->title;
$edit['weight'] = $item->weight;
- $edit['visibility'] = $item->visibility;
- $edit['status'] = $item->status;
+ $edit['type'] = $item->type;
}
else {
$edit['mid'] = 0; // In case a negative ID was passed in.
$edit['pid'] = 1; // default to "Navigation" menu.
- $edit['status'] = MENU_CUSTOM;
+ $edit['type'] = MENU_CUSTOM_ITEM;
}
$output .= menu_edit_item_form($edit);
}
@@ -223,11 +253,12 @@ function menu_edit_item_form($edit) {
$form .= form_hidden('weight', 0);
}
else {
- if ($edit['status'] == MENU_CUSTOM) {
+ if ($edit['type'] & MENU_CREATED_BY_ADMIN) {
$form .= form_textfield(t('Path'), 'path', $edit['path'], 60, 128);
}
else {
$form .= form_item(t('Path'), l($edit['path'], $edit['path']));
+ $form .= form_hidden('path', $edit['path']);
}
// Generate a list of possible parents (not including this item or descendants).
@@ -240,14 +271,8 @@ function menu_edit_item_form($edit) {
$form .= form_submit(t('Submit'));
$form .= form_hidden('mid', $edit['mid']);
- $form .= form_hidden('status', $edit['status']);
- if ($edit['visibility'] == MENU_HIDE) {
- // always enable on edit
- $form .= form_hidden('visibility', MENU_SHOW);
- }
- else {
- $form .= form_hidden('visibility', $edit['visibility']);
- }
+ // Always enable menu items when editing them.
+ $form .= form_hidden('type', $edit['type'] | MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB);
return form($form);
}
@@ -257,17 +282,12 @@ function menu_edit_item_form($edit) {
*/
function menu_edit_item_save($edit) {
if ($edit['mid']) {
- if ($edit['status'] == MENU_CUSTOM) {
- db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', weight = %d, visibility = %d WHERE mid = %d", $edit['pid'], $edit['path'], $edit['title'], $edit['weight'], $edit['visibility'], $edit['mid']);
- }
- else {
- db_query("UPDATE {menu} SET pid = %d, title = '%s', weight = %d, visibility = %d, status = %d WHERE mid = %d", $edit['pid'], $edit['title'], $edit['weight'], $edit['visibility'], MENU_MODIFIED, $edit['mid']);
- }
+ db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', weight = %d, type = %d WHERE mid = %d", $edit['pid'], $edit['path'], $edit['title'], $edit['weight'], $edit['type'] | MENU_MODIFIED_BY_ADMIN, $edit['mid']);
drupal_set_message(t('updated menu item "%title".', array('%title' => $edit['title'])));
}
else {
$mid = db_next_id('menu_mid');
- db_query("INSERT INTO {menu} (mid, pid, path, title, weight, visibility, status) VALUES (%d, %d, '%s', '%s', %d, %d, %d)", $mid, $edit['pid'], $edit['path'], $edit['title'], $edit['weight'], $edit['visibility'], $edit['status']);
+ db_query("INSERT INTO {menu} (mid, pid, path, title, weight, type) VALUES (%d, %d, '%s', '%s', %d, %d)", $mid, $edit['pid'], $edit['path'], $edit['title'], $edit['weight'], $edit['type'] | MENU_MODIFIED_BY_ADMIN);
drupal_set_message(t('created new menu item "%title".', array('%title' => $edit['title'])));
}
@@ -284,10 +304,10 @@ function menu_overview_tree() {
foreach ($menu['items'][0]['children'] as $mid) {
$operations = array();
- if ($menu['items'][$mid]['status'] != MENU_LOCKED) {
+ if ($menu['items'][$mid]['type'] & MENU_MODIFIABLE_BY_ADMIN) {
$operations[] = l(t('edit'), 'admin/menu/item/edit/'. $mid);
}
- if ($menu['items'][$mid]['status'] == MENU_CUSTOM) {
+ if ($menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
$operations[] = l(t('delete'), 'admin/menu/item/delete/'. $mid);
}
$table = theme('item_list', $operations);
@@ -324,17 +344,13 @@ function menu_overview_tree_rows($pid = 0, $depth = 0) {
// Populate the operations field.
$operations = array();
- if ($menu['items'][$mid]['status'] == MENU_LOCKED) {
+ if (!($menu['items'][$mid]['type'] & MENU_MODIFIABLE_BY_ADMIN)) {
$operations[] = array('data' => t('locked'), 'colspan' => 3, 'align' => 'center');
}
else {
- if ($menu['items'][$mid]['visibility'] == MENU_HIDE) {
- $operations[] = array('data' => '');
- $operations[] = array('data' => l(t('enable'), 'admin/menu/item/edit/'. $mid));
- }
- else {
+ if ($menu['items'][$mid]['type'] & MENU_VISIBLE_IN_TREE) {
$operations[] = array('data' => l(t('edit'), 'admin/menu/item/edit/'. $mid));
- if ($pid == 0) {
+ if ($menu['items'][$mid]['type'] & MENU_IS_ROOT) {
// Disabling entire menus is done from block admin page.
$operations[] = array('data' => '');
}
@@ -342,32 +358,32 @@ function menu_overview_tree_rows($pid = 0, $depth = 0) {
$operations[] = array('data' => l(t('disable'), 'admin/menu/item/disable/'. $mid));
}
}
-
- if ($menu['items'][$mid]['status'] == MENU_MODIFIED) {
- $operations[] = array('data' => l(t('reset'), 'admin/menu/item/reset/'. $mid));
+ else {
+ $operations[] = array('data' => '');
+ $operations[] = array('data' => l(t('enable'), 'admin/menu/item/edit/'. $mid));
}
- else if ($menu['items'][$mid]['status'] == MENU_CUSTOM) {
+
+ if ($menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
$operations[] = array('data' => l(t('delete'), 'admin/menu/item/delete/'. $mid));
}
+ else if ($menu['items'][$mid]['type'] & MENU_MODIFIED_BY_ADMIN) {
+ $operations[] = array('data' => l(t('reset'), 'admin/menu/item/reset/'. $mid));
+ }
else {
$operations[] = array('data' => '');
}
}
// Call out disabled items.
- if ($menu['items'][$mid]['visibility'] == MENU_HIDE) {
- $title .= ' ('. t('disabled') .')';
- $class = 'menu-disabled';
+ if ($menu['items'][$mid]['type'] & MENU_VISIBLE_IN_TREE) {
+ $class = 'menu-enabled';
}
else {
- $class = 'menu-enabled';
+ $title .= ' ('. t('disabled') .')';
+ $class = 'menu-disabled';
}
- if ($menu['items'][$mid]['visibility'] == MENU_HIDE && $menu['items'][$mid]['status'] == MENU_LOCKED) {
- // Skip items that are hidden and locked; admins will never care about them.
- $rows = array_merge($rows, menu_overview_tree_rows($mid, $depth));
- }
- else {
+ if ($menu['items'][$mid]['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_VISIBLE_IN_TREE)) {
$row = array(array('data' => $title, 'class' => $class));
foreach ($operations as $operation) {
$operation['class'] = $class;
@@ -376,6 +392,10 @@ function menu_overview_tree_rows($pid = 0, $depth = 0) {
$rows[] = $row;
$rows = array_merge($rows, menu_overview_tree_rows($mid, $depth + 1));
}
+ else {
+ // Skip items that are hidden and locked; admins will never care about them.
+ $rows = array_merge($rows, menu_overview_tree_rows($mid, $depth));
+ }
}
}
@@ -396,12 +416,12 @@ function menu_parent_options($mid, $pid = 0, $depth = 0) {
usort($menu['items'][$pid]['children'], '_menu_sort');
foreach ($menu['items'][$pid]['children'] as $child) {
if ($child != $mid) {
- if ($child == 1 || ($child > 0 && $menu['items'][$child]['status'] != MENU_LOCKED)) {
+ if ($child == 1 || ($child > 0 && ($menu['items'][$child]['type'] & MENU_MODIFIABLE_BY_ADMIN))) {
$title = ' '. $menu['items'][$child]['title'];
for ($i = 0; $i < $depth; $i++) {
$title = '--'. $title;
}
- if ($menu['items'][$child]['visibility'] == MENU_HIDE) {
+ if (!($menu['items'][$child]['type'] & MENU_VISIBLE_IN_TREE)) {
$title .= ' ('. t('disabled') .')';
}
$options[$child] = $title;