734 lines
26 KiB
Plaintext
734 lines
26 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Allows administrators to customize the site navigation menu.
|
|
*/
|
|
|
|
/**
|
|
* Implementation of hook_menu().
|
|
*/
|
|
function menu_menu($may_cache) {
|
|
$items = array();
|
|
|
|
if ($may_cache) {
|
|
$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);
|
|
|
|
$items[] = array('path' => 'admin/menu/list', 'title' => t('list'),
|
|
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
|
|
$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);
|
|
|
|
$items[] = array('path' => 'admin/settings/menu',
|
|
'title' => t('menus'),
|
|
'callback' => 'menu_configure',
|
|
'access' => user_access('administer menu'));
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_help().
|
|
*/
|
|
function menu_help($section) {
|
|
switch ($section) {
|
|
case 'admin/help#menu':
|
|
$output = t('<p>The menu module allows for customization of the menus. Menus are useful for providing navigation in your site. The main menu for navigation is the navigation menu. Menus appear in blocks on your site.</p>
|
|
<ul>
|
|
<li>On the administer menu page administrators can \'\'\'edit\'\'\' to change the title, description, parent or weight of the menu item. Under the \'\'\'operations\'\'\' column, click on \'\'\'enable/disable\'\'\' to toggle the menu item on or off. Menu items which are disabled are not deleted; they are merely not available for navigating the site in the sidebar menu block. Note that the default menu items generated by the menu module cannot be deleted, only disabled.</li>
|
|
<li>Using the \'\'\'add menu\'\'\' tab submit a title for a new custom menu. Once submitted, the new menu will appear in a list toward the bottom of the administer menu page underneath the main navigation menu.</li>
|
|
<li>Use the \'\'\'add menu item\'\'\' tab to create new links in either the navigation or a custom menu. Select the parent item to place the new link within an existing menu structure. For top level menu items, choose the name of the menu in which the link is to be added.</li>
|
|
<li>To turn off the navigation menu block, administer the block page.</li>
|
|
</ul>
|
|
');
|
|
$output .= t('<p>You can</p>
|
|
<ul>
|
|
<li>administer menus at <a href="%admin-menu"> administer >> menus</a>.</li>
|
|
<li>turn menus blocks on and off in the <a href="%admin-block">administration >> block</a>.</li>
|
|
<li>add a menu at <a href="%admin-menu-menu-add">administer >> menus >> add menu</a>.</li>
|
|
<li>add a menu item at <a href="%admin-menu-item-add">administer >> menus >> add menu item</a>.</li>
|
|
</ul>
|
|
', array('%admin-menu' => url('admin/menu'), '%admin-block' => url('admin/block'), '%admin-menu-menu-add' => url('admin/menu/menu/add'), '%admin-menu-item-add' => url('admin/menu/item/add')));
|
|
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%menu">Menu page</a>.', array('%menu' => 'http://www.drupal.org/handbook/modules/menu/')) .'</p>';
|
|
return $output;
|
|
case 'admin/modules#description':
|
|
return t('Allows administrators to customize the site navigation menu.');
|
|
case 'admin/menu':
|
|
return t('<p>Select an operation from the list to move, change, or delete a menu item.</p>');
|
|
case 'admin/menu/menu/add':
|
|
return t('<p>Enter the name for your new menu. Remember to enable the newly created block in the %blocks administration page.</p>', array('%blocks' => l(t('blocks'), 'admin/block')));
|
|
case 'admin/menu/item/add':
|
|
return t('<p>Enter the title, path, position and the weight for your new menu item.</p>');
|
|
case 'admin/settings/menu':
|
|
return t('<p>Customize the menu settings.</p>');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Menu callback; presents menu configuration options.
|
|
*/
|
|
function menu_configure() {
|
|
$menu = menu_get_menu();
|
|
|
|
$primary_options[0] = t('No primary links');
|
|
foreach ($menu['items'][0]['children'] as $mid) {
|
|
$primary_options[$mid] = $menu['items'][$mid]['title'];
|
|
}
|
|
|
|
$form['settings_links'] = array(
|
|
'#type' => 'fieldset',
|
|
'#title' => t('Primary links settings'),
|
|
);
|
|
|
|
$form['settings_links']['intro'] = array(
|
|
'#type' => 'item',
|
|
'#value' => t('Primary links is a navigation system which usually (depending on your theme) appears at the top-right of the browser window. There are usually two rows of links, primary and secondary. You may control which links appear in this area by choosing a menu from which the links will be generated and then placing your links into the menu using the <a href="%menu">menu administration</a> or the menu settings pane on each post authoring form.', array('%menu' => url('admin/menu'))),
|
|
);
|
|
|
|
$form['settings_links']['menu_primary_menu'] = array(
|
|
'#type' => 'select',
|
|
'#title' => t('Menu containing primary links'),
|
|
'#default_value' => variable_get('menu_primary_menu', 0),
|
|
'#options' => $primary_options,
|
|
);
|
|
|
|
$secondary_options[0] = t('No secondary links');
|
|
foreach ($menu['items'][0]['children'] as $mid) {
|
|
$secondary_options[$mid] = $menu['items'][$mid]['title'];
|
|
}
|
|
|
|
$form['settings_links']['menu_secondary_menu'] = array(
|
|
'#type' => 'select',
|
|
'#title' => t('Menu containing secondary links'),
|
|
'#default_value' => variable_get('menu_secondary_menu', 0),
|
|
'#options' => $secondary_options,
|
|
'#description' => t('If you select the same menu as primary links then secondary links will display the appropriate second level of your navigation hierarchy.'),
|
|
);
|
|
|
|
$form['settings_authoring'] = array(
|
|
'#type' => 'fieldset',
|
|
'#title' => t('Post authoring form settings'),
|
|
);
|
|
|
|
$form['settings_authoring']['intro'] = array(
|
|
'#type' => 'item',
|
|
'#value' => t('On each post authoring form there is a menu settings pane. This setting allows you to limit what is displayed in the parent item drop-down menu of that pane. This can be used to force new menu items to be created in the primary links menu or to hide admin menu items.'),
|
|
);
|
|
|
|
$authoring_options = array(0 => t('Show all menus'));
|
|
foreach ($menu['items'][0]['children'] as $mid) {
|
|
$authoring_options[$mid] = $menu['items'][$mid]['title'];
|
|
}
|
|
|
|
$form['settings_authoring']['menu_parent_items'] = array(
|
|
'#type' => 'select',
|
|
'#title' => t('Restrict parent items to'),
|
|
'#default_value' => variable_get('menu_parent_items', 0),
|
|
'#options' => $authoring_options,
|
|
'#description' => t('Choose the menu from which parent items will be made available. Only this menu item and its children will be shown.'),
|
|
);
|
|
|
|
return system_settings_form('menu_configure', $form);
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_block().
|
|
*/
|
|
function menu_block($op = 'list', $delta = 0) {
|
|
$menu = menu_get_menu();
|
|
|
|
if ($op == 'list') {
|
|
$blocks = array();
|
|
foreach ($menu['items'][0]['children'] as $mid) {
|
|
// Default "Navigation" block is handled by user.module.
|
|
if ($mid != 1) {
|
|
$blocks[$mid]['info'] = $menu['items'][$mid]['title'];
|
|
}
|
|
}
|
|
return $blocks;
|
|
}
|
|
else if ($op == 'view') {
|
|
$data['subject'] = $menu['items'][$delta]['title'];
|
|
$data['content'] = '<div class="menu">'. theme('menu_tree', $delta) .'</div>' ;
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_nodeapi().
|
|
*/
|
|
function menu_nodeapi(&$node, $op) {
|
|
|
|
if (user_access('administer menu')) {
|
|
switch ($op) {
|
|
case 'insert':
|
|
case 'update':
|
|
if ($node->menu['delete']) {
|
|
menu_node_form_delete($node);
|
|
menu_rebuild();
|
|
}
|
|
elseif ($node->menu['title']) {
|
|
$node->menu['path'] = ($node->menu['path']) ? $node->menu['path'] : "node/$node->nid";
|
|
menu_edit_item_save($node->menu);
|
|
menu_rebuild();
|
|
}
|
|
break;
|
|
|
|
case 'delete':
|
|
menu_node_form_delete($node);
|
|
menu_rebuild();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_perm().
|
|
*/
|
|
function menu_perm() {
|
|
return array('administer menu');
|
|
}
|
|
|
|
/**
|
|
* Menu callback; present the main menu management page.
|
|
*/
|
|
function menu_overview() {
|
|
menu_rebuild();
|
|
|
|
return menu_overview_tree();
|
|
}
|
|
|
|
/**
|
|
* Menu callback; clear the database, resetting the menu to factory defaults.
|
|
*/
|
|
function menu_reset() {
|
|
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
|
switch ($op) {
|
|
case t('Reset all'):
|
|
db_query('DELETE FROM {menu}');
|
|
drupal_set_message(t('The menu items have been reset to their default settings.'));
|
|
drupal_goto('admin/menu');
|
|
break;
|
|
default:
|
|
return confirm_form('menu_confirm_reset', array(),
|
|
t('Are you sure you want to reset all menu items to their default settings?'),
|
|
'admin/menu', t('Any custom additions or changes to the menu will be lost.'),
|
|
t('Reset all'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Menu callback; handle the adding of a new menu.
|
|
*/
|
|
function menu_add_menu() {
|
|
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
|
$edit = isset($_POST['edit']) ? $_POST['edit'] : '';
|
|
$output = '';
|
|
|
|
switch ($op) {
|
|
case t('Submit'):
|
|
menu_edit_item_validate($edit);
|
|
if (!form_get_errors()) {
|
|
menu_edit_item_save($edit);
|
|
drupal_goto('admin/menu');
|
|
}
|
|
// Fall through.
|
|
default:
|
|
$edit['pid'] = 0;
|
|
$edit['type'] = MENU_CUSTOM_MENU;
|
|
$output .= menu_edit_item_form($edit);
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Menu callback; reset a single modified item.
|
|
*/
|
|
function menu_reset_item($mid) {
|
|
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
|
switch ($op) {
|
|
case t('Reset'):
|
|
db_query('DELETE FROM {menu} WHERE mid = %d', $mid);
|
|
drupal_set_message(t("The menu item was reset to its default settings."));
|
|
drupal_goto('admin/menu');
|
|
break;
|
|
default:
|
|
$title = db_result(db_query('SELECT title FROM {menu} WHERE mid = %d', $mid));
|
|
return confirm_form('menu_item_confirm_reset', array(),
|
|
t('Are you sure you want to reset the item %item to its default values?', array('%item' => theme('placeholder', $title))),
|
|
'admin/menu', t('Any customizations will be lost. This action cannot be undone.'),
|
|
t('Reset'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Menu callback; delete a single custom item.
|
|
*/
|
|
function menu_delete_item($mid) {
|
|
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
|
$result = db_query('SELECT type, title FROM {menu} WHERE mid = %d', $mid);
|
|
$menu = db_fetch_object($result);
|
|
if (!$menu) {
|
|
drupal_goto('admin/menu');
|
|
}
|
|
switch ($op) {
|
|
case t('Delete'):
|
|
db_query('DELETE FROM {menu} WHERE mid = %d', $mid);
|
|
if ($menu->type & MENU_IS_ROOT) {
|
|
drupal_set_message(t('The menu has been removed.'));
|
|
}
|
|
else {
|
|
drupal_set_message(t('The menu item has been removed.'));
|
|
}
|
|
drupal_goto('admin/menu');
|
|
break;
|
|
default:
|
|
if ($menu->type & MENU_IS_ROOT) {
|
|
$message = t('Are you sure you want to delete the menu %item?', array('%item' => theme('placeholder', $menu->title)));
|
|
}
|
|
else {
|
|
$message = t('Are you sure you want to delete the custom menu item %item?', array('%item' => theme('placeholder', $menu->title)));
|
|
}
|
|
return confirm_form('menu_confirm_delete', $form, $message, 'admin/menu', t('This action cannot be undone.'), t('Delete'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Menu callback; hide a menu item.
|
|
*/
|
|
function menu_disable_item($mid) {
|
|
$menu = menu_get_menu();
|
|
$type = $menu['items'][$mid]['type'];
|
|
$type &= ~MENU_VISIBLE_IN_TREE;
|
|
$type &= ~MENU_VISIBLE_IN_BREADCRUMB;
|
|
$type |= MENU_MODIFIED_BY_ADMIN;
|
|
db_query('UPDATE {menu} SET type = %d WHERE mid = %d', $type, $mid);
|
|
drupal_set_message(t('The menu item has been disabled.'));
|
|
drupal_goto('admin/menu');
|
|
}
|
|
|
|
/**
|
|
* Menu callback; dispatch to the appropriate menu item edit function.
|
|
*/
|
|
function menu_edit_item($mid = 0) {
|
|
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
|
$edit = isset($_POST['edit']) ? $_POST['edit'] : '';
|
|
|
|
$output = '';
|
|
|
|
switch ($op) {
|
|
case t('Submit'):
|
|
menu_edit_item_validate($edit);
|
|
if (!form_get_errors()) {
|
|
menu_edit_item_save($edit);
|
|
drupal_goto('admin/menu');
|
|
}
|
|
$output .= menu_edit_item_form($edit);
|
|
break;
|
|
default:
|
|
if ($mid > 0) {
|
|
$item = db_fetch_object(db_query('SELECT * FROM {menu} WHERE mid = %d', $mid));
|
|
|
|
$edit['mid'] = $item->mid;
|
|
$edit['pid'] = $item->pid;
|
|
$edit['path'] = $item->path;
|
|
$edit['title'] = $item->title;
|
|
$edit['description'] = $item->description;
|
|
$edit['weight'] = $item->weight;
|
|
$edit['type'] = $item->type;
|
|
}
|
|
else {
|
|
$edit['mid'] = 0; // In case a negative ID was passed in.
|
|
$edit['pid'] = 1; // default to "Navigation" menu.
|
|
$edit['type'] = MENU_CUSTOM_ITEM;
|
|
}
|
|
$output .= menu_edit_item_form($edit);
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Present the menu item editing form.
|
|
*/
|
|
function menu_edit_item_form($edit) {
|
|
$menu = menu_get_menu();
|
|
|
|
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $edit['title'], '#description' => t('The name of the menu.'), '#required' => TRUE);
|
|
|
|
if ($edit['pid'] == 0) {
|
|
// Display a limited set of fields for menus (not items).
|
|
$form['path'] = array('#type' => 'hidden', '#value' => '');
|
|
$form['pid'] = array('#type' => 'hidden', '#value' => 0);
|
|
$form['weight'] = array('#type' => 'hidden', '#value' => 0);
|
|
}
|
|
else {
|
|
$form['description'] = array('#type' => 'textfield', '#title' => t('Description'), '#default_value' => $edit['description'], '#description' => t('The description displayed when hovering over a menu item.'));
|
|
|
|
$path_description = t('The Drupal path this menu item links to.');
|
|
|
|
if ($edit['type'] & MENU_CREATED_BY_ADMIN) {
|
|
$form['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#default_value' => $edit['path'], '#description' => $path_description, '#required' => TRUE);
|
|
}
|
|
else {
|
|
$form['_path'] = array('#type' => 'item', '#title' => t('Path'), '#title' => l($edit['path'], $edit['path']));
|
|
$form['path'] = array('#type' => 'hidden', '#value' => $edit['path']);
|
|
}
|
|
$expanded = $edit['type'] & MENU_EXPANDED ? 1 : 0;
|
|
$form['expanded'] = array('#type' => 'checkbox', '#title' => t('Expanded'), '#default_value' => $expanded, '#description' => t('If selected and this menu item has children, the menu will always appear expanded.'));
|
|
|
|
// Generate a list of possible parents (not including this item or descendants).
|
|
$options = menu_parent_options($edit['mid']);
|
|
$form['pid'] = array('#type' => 'select', '#title' => t('Parent item'), '#default_value' => $edit['pid'], '#options' => $options);
|
|
|
|
$form['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $edit['weight'], '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'));
|
|
}
|
|
|
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
|
|
|
|
$form['mid'] = array('#type' => 'hidden', '#value' => $edit['mid']);
|
|
|
|
// Always enable menu items (but not menus) when editing them.
|
|
if (!($edit['type'] & MENU_IS_ROOT)) {
|
|
$edit['type'] |= MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB;
|
|
}
|
|
|
|
$form['type'] = array('#type' => 'hidden', '#value' => $edit['type']);
|
|
|
|
return drupal_get_form('menu_edit_item_form', $form);
|
|
}
|
|
|
|
/**
|
|
* Confirm that an edited menu item has fields properly filled in.
|
|
*/
|
|
function menu_edit_item_validate($edit) {
|
|
if (empty($edit['title'])) {
|
|
form_set_error('title', t('You must specify a title.'));
|
|
}
|
|
|
|
if ($edit['pid'] != 0) {
|
|
if (empty($edit['path'])) {
|
|
form_set_error('path', t('You must specify a path.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save changes to a menu item into the database.
|
|
*/
|
|
function menu_edit_item_save($edit) {
|
|
$menu = menu_get_menu();
|
|
|
|
if ($edit['expanded']) {
|
|
$edit['type'] |= MENU_EXPANDED;
|
|
}
|
|
else {
|
|
$edit['type'] &= ~MENU_EXPANDED;
|
|
}
|
|
|
|
if ($edit['mid']) {
|
|
db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d WHERE mid = %d", $edit['pid'], $edit['path'], $edit['title'], $edit['description'], $edit['weight'], $edit['type'] | MENU_MODIFIED_BY_ADMIN, $edit['mid']);
|
|
drupal_set_message(t('The menu item %title has been updated.', array('%title' => theme('placeholder', $edit['title']))));
|
|
}
|
|
else {
|
|
$mid = db_next_id('{menu}_mid');
|
|
db_query("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)", $mid, $edit['pid'], $edit['path'], $edit['title'], $edit['description'], $edit['weight'], $edit['type'] | MENU_MODIFIED_BY_ADMIN);
|
|
drupal_set_message(t('The menu item %title has been created.', array('%title' => theme('placeholder', $edit['title']))));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Present the menu tree, rendered along with links to edit menu items.
|
|
*/
|
|
function menu_overview_tree() {
|
|
$menu = menu_get_menu();
|
|
$header = array(t('Menu item'), t('Expanded'), array('data' => t('Operations'), 'colspan' => '3'));
|
|
$output = '';
|
|
|
|
foreach ($menu['items'][0]['children'] as $mid) {
|
|
$operations = array();
|
|
if ($menu['items'][$mid]['type'] & MENU_MODIFIABLE_BY_ADMIN) {
|
|
$operations[] = l(t('edit'), 'admin/menu/item/edit/'. $mid);
|
|
}
|
|
if ($menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
|
|
$operations[] = l(t('delete'), 'admin/menu/item/delete/'. $mid);
|
|
}
|
|
$table = theme('item_list', $operations);
|
|
$table .= theme('table', $header, menu_overview_tree_rows($mid));
|
|
$output .= theme('box', $menu['items'][$mid]['title'], $table);
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
function menu_overview_tree_rows($pid = 0, $depth = 0) {
|
|
$menu = menu_get_menu();
|
|
|
|
$rows = array();
|
|
|
|
if (isset($menu['items'][$pid]) && isset($menu['items'][$pid]['children'])) {
|
|
|
|
usort($menu['items'][$pid]['children'], '_menu_sort');
|
|
foreach ($menu['items'][$pid]['children'] as $mid) {
|
|
// Populate the title field.
|
|
$title = '';
|
|
if ($pid == 0) {
|
|
// Top-level items are menu names, and don't have an associated path.
|
|
$title .= $menu['items'][$mid]['title'];
|
|
}
|
|
else {
|
|
$title .= l($menu['items'][$mid]['title'], $menu['items'][$mid]['path']);
|
|
}
|
|
if ($depth > 0) {
|
|
$title = '- '. $title;
|
|
}
|
|
for ($i = 1; $i < $depth; $i++) {
|
|
$title = ' '. $title;
|
|
}
|
|
|
|
// Populate the operations field.
|
|
$operations = array();
|
|
if (!($menu['items'][$mid]['type'] & MENU_MODIFIABLE_BY_ADMIN)) {
|
|
$operations[] = array('data' => t('locked'), 'colspan' => '3', 'align' => 'center');
|
|
}
|
|
else {
|
|
// Set the edit column.
|
|
if ($menu['items'][$mid]['type'] & (MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IF_HAS_CHILDREN)) {
|
|
$operations[] = array('data' => l(t('edit'), 'admin/menu/item/edit/'. $mid));
|
|
}
|
|
else {
|
|
$operations[] = array('data' => '');
|
|
}
|
|
|
|
// Set the disable column.
|
|
if ($menu['items'][$mid]['type'] & (MENU_IS_ROOT | MENU_VISIBLE_IF_HAS_CHILDREN)) {
|
|
// Disabling entire menus is done from block admin page.
|
|
// MENU_VISIBLE_IF_HAS_CHILDREN menus are always enabled so hide this operation.
|
|
$operations[] = array('data' => '');
|
|
}
|
|
else if ($menu['items'][$mid]['type'] & MENU_VISIBLE_IN_TREE) {
|
|
$operations[] = array('data' => l(t('disable'), 'admin/menu/item/disable/'. $mid));
|
|
}
|
|
else {
|
|
$operations[] = array('data' => l(t('enable'), 'admin/menu/item/edit/'. $mid));
|
|
}
|
|
|
|
// Set the reset column.
|
|
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]['type'] & (MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IF_HAS_CHILDREN)) {
|
|
$class = 'menu-enabled';
|
|
}
|
|
else {
|
|
$title .= ' ('. t('disabled') .')';
|
|
$class = 'menu-disabled';
|
|
}
|
|
|
|
if ($menu['items'][$mid]['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_VISIBLE_IN_TREE)) {
|
|
$row = array(array('data' => $title, 'class' => $class), array('data' => ($menu['items'][$mid]['children'] ? (($menu['items'][$mid]['type'] & MENU_EXPANDED) ? t('Yes') : t('No')) : ''), 'class' => $class));
|
|
foreach ($operations as $operation) {
|
|
$operation['class'] = $class;
|
|
$row[] = $operation;
|
|
}
|
|
$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));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
/**
|
|
* Return a list of menu items that are valid possible parents for the
|
|
* given menu item. The list excludes the given item and its children.
|
|
*
|
|
* @param $mid
|
|
* The menu item id for which to generate a list of parents.
|
|
* If $mid == 0 then the complete tree is returned.
|
|
* @param $pid
|
|
* The menu item id of the menu item at which to start the tree.
|
|
* If $pid > 0 then this item will be included in the tree.
|
|
* @param $depth
|
|
* The current depth in the tree - used when recursing to indent the tree.
|
|
* @return
|
|
* An array of menu titles keyed on the mid.
|
|
*/
|
|
function menu_parent_options($mid, $pid = 0, $depth = 0) {
|
|
$menu = menu_get_menu();
|
|
|
|
$options = array();
|
|
|
|
if (!isset($menu['items'][$pid])) {
|
|
return $options;
|
|
}
|
|
|
|
// Exclude $mid and its children from the list unless $mid is 0.
|
|
if ($mid && $mid == $pid) {
|
|
return $options;
|
|
}
|
|
|
|
// Add the current $pid to the list.
|
|
if ($pid > 0 && ($menu['items'][$pid]['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_IS_ROOT))) {
|
|
$title = ' '. $menu['items'][$pid]['title'];
|
|
for ($i = 0; $i < $depth; $i++) {
|
|
$title = '--'. $title;
|
|
}
|
|
if (!($menu['items'][$pid]['type'] & MENU_VISIBLE_IN_TREE)) {
|
|
$title .= ' ('. t('disabled') .')';
|
|
}
|
|
$options[$pid] = $title;
|
|
$depth ++;
|
|
}
|
|
|
|
// Add children of $pid to the list recursively.
|
|
if ($menu['items'][$pid]['children']) {
|
|
usort($menu['items'][$pid]['children'], '_menu_sort');
|
|
foreach ($menu['items'][$pid]['children'] as $child) {
|
|
$options += menu_parent_options($mid, $child, $depth);
|
|
}
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* Add menu item fields to the node form.
|
|
*/
|
|
function menu_form_alter($form_id, &$form) {
|
|
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
|
|
$edit = isset($_POST['edit']) ? $_POST['edit'] : '';
|
|
$edit['nid'] = $form['nid']['#value'];
|
|
|
|
$item = array();
|
|
if ($edit['nid'] > 0) {
|
|
$item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'node/%d'", $edit['nid']));
|
|
if (is_array($edit['menu'])) {
|
|
$item = !is_array($item) ? $edit['menu'] : (($_POST['op'] == t('Preview')) ? array_merge($item, $edit['menu']) : array_merge($edit['menu'], $item));
|
|
}
|
|
}
|
|
|
|
$form['menu'] = array(
|
|
'#type' => 'fieldset',
|
|
'#title' => t('Menu settings'),
|
|
'#collapsible' => TRUE,
|
|
'#collapsed' => TRUE,
|
|
'#tree' => TRUE,
|
|
);
|
|
|
|
$form['menu']['title'] = array(
|
|
'#type' => 'textfield',
|
|
'#title' => t('Title'),
|
|
'#default_value' => $item['title'],
|
|
'#description' => t('The name to display for this link.'),
|
|
);
|
|
|
|
$form['menu']['description'] = array(
|
|
'#type' => 'textfield',
|
|
'#title' => t('Description'),
|
|
'#default_value' => $item['description'],
|
|
'#description' => t('The description displayed when hovering over a menu item.'),
|
|
);
|
|
|
|
// Generate a list of possible parents.
|
|
$options = menu_parent_options($item['mid'], variable_get('menu_parent_items', 0));
|
|
|
|
$form['menu']['pid'] = array(
|
|
'#type' => select,
|
|
'#title' => t('Parent item'),
|
|
'#default_value' => $item['pid'],
|
|
'#options' => $options,
|
|
);
|
|
|
|
$form['menu']['path'] = array(
|
|
'#type' => 'hidden',
|
|
'#value' => $item['path'],
|
|
);
|
|
|
|
$form['menu']['weight'] = array(
|
|
'#type' => 'weight',
|
|
'#title' => t('Weight'),
|
|
'#default_value' => $item['weight'],
|
|
'#delta' => 10,
|
|
'#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'),
|
|
);
|
|
|
|
$form['menu']['mid'] = array(
|
|
'#type' => 'hidden',
|
|
'#value' => $item['mid'] ? $item['mid'] : 0,
|
|
);
|
|
|
|
$form['menu']['type'] = array(
|
|
'#type' => 'hidden',
|
|
'#value' => $item['type'] ? $item['type'] : MENU_CUSTOM_ITEM,
|
|
);
|
|
|
|
if ($item['mid'] > 0) {
|
|
$form['menu']['delete'] = array(
|
|
'#type' => 'checkbox',
|
|
'#title' => t('Check to delete this menu item.'),
|
|
'#default_value' => $item['delete'],
|
|
);
|
|
|
|
$form['menu']['advanced'] = array(
|
|
'#type' => 'item',
|
|
'#value' => t('You may also <a href="%edit">edit the advanced settings</a> for this menu item.', array('%edit' => url("admin/menu/item/edit/{$item['mid']}"))),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the menu item.
|
|
*/
|
|
function menu_node_form_delete($node) {
|
|
db_query("DELETE FROM {menu} WHERE path = 'node/%s'", $node->nid);
|
|
}
|
|
|