Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.185 diff -u -p -r1.185 menu.inc --- includes/menu.inc 5 Jul 2007 08:48:57 -0000 1.185 +++ includes/menu.inc 6 Jul 2007 23:44:02 -0000 @@ -1361,7 +1361,7 @@ function _menu_navigation_links_rebuild( array_multisort($sort, SORT_NUMERIC, $menu_links); foreach ($menu_links as $item) { - $existing_item = db_fetch_array(db_query("SELECT mlid, customized FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s' AND module = 'system'", $item['menu_name'], $item['link_path'])); + $existing_item = db_fetch_array(db_query("SELECT mlid, customized FROM {menu_links} WHERE link_path = '%s' AND module = 'system'", $item['link_path'])); if ($existing_item) { $item['mlid'] = $existing_item['mlid']; } Index: modules/menu/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v retrieving revision 1.125 diff -u -p -r1.125 menu.module --- modules/menu/menu.module 5 Jul 2007 08:48:57 -0000 1.125 +++ modules/menu/menu.module 6 Jul 2007 23:44:02 -0000 @@ -146,7 +146,7 @@ function menu_load($menu_name) { * Menu callback which shows an overview page of all the custom menus and their descriptions. */ function menu_overview_page() { - $result = db_query("SELECT * FROM {menu_custom}"); + $result = db_query("SELECT * FROM {menu_custom} ORDER BY title"); $content = array(); while ($menu = db_fetch_array($result)) { $menu['href'] = 'admin/build/menu-customize/'. $menu['menu_name']; @@ -256,7 +256,7 @@ function menu_edit_item(&$form_state, $t // This is an add form, initialize the menu link. $item = array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu['menu_name'], 'weight' => 0, 'link_path' => '', 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0); } - foreach (array('link_path', 'mlid', 'module', 'hidden', 'menu_name', 'has_children', 'options') as $key) { + foreach (array('link_path', 'mlid', 'module', 'hidden', 'has_children', 'options') as $key) { $form[$key] = array('#type' => 'value', '#value' => $item[$key]); } // Any item created or edited via this interface is considered "customized". @@ -271,6 +271,13 @@ function menu_edit_item(&$form_state, $t '#description' => t('The path this menu item links to. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), '#required' => TRUE, ); + $form['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + '#access' => $item['mlid'], + '#submit' => array('menu_item_delete_submit'), + '#weight' => 10, + ); } else { $form['_path'] = array( @@ -300,11 +307,15 @@ function menu_edit_item(&$form_state, $t ); // Generate a list of possible parents (not including this item or descendants). - $options = menu_parent_options($item['menu_name'], $item); - $form['plid'] = array( + $options = menu_parent_options($item); + $default = $item['menu_name'] .':'. $item['plid']; + if (!isset($options[$default])) { + $default = 'navigation:0'; + } + $form['parent'] = array( '#type' => 'select', '#title' => t('Parent item'), - '#default_value' => $item['plid'], + '#default_value' => $default, '#options' => $options, ); $form['weight'] = array( @@ -315,6 +326,7 @@ function menu_edit_item(&$form_state, $t ); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); + return $form; } @@ -329,10 +341,18 @@ function menu_edit_item_validate($form, } /** + * Submit function for the delete button on the menu item editing form. + */ +function menu_item_delete_submit($form, &$form_state) { + $form_state['redirect'] = 'admin/build/menu/item/'. $form_state['values']['mlid'] .'/delete'; +} + +/** * Process menu and menu item add/edit form submissions. */ function menu_edit_item_submit($form, &$form_state) { $form_state['values']['options']['attributes']['title'] = $form_state['values']['description']; + list($form_state['values']['menu_name'], $form_state['values']['plid']) = explode(':', $form_state['values']['parent']); menu_link_save($form_state['values']); $form_state['redirect'] = 'admin/build/menu-customize/'. $form_state['values']['menu_name']; } @@ -349,28 +369,29 @@ function menu_edit_item_submit($form, &$ * @return * An array of menu link titles keyed on the mlid. */ -function menu_parent_options($menu_name, $item) { - - $tree = menu_tree_all_data($item['menu_name'], NULL, TRUE); - $options = array(0 => '<'. t('root') .'>'); - _menu_parents_recurse($tree, '--', $options, $item['mlid']); - +function menu_parent_options($item) { + $menus = menu_get_menus(TRUE); + foreach ($menus as $menu_name => $title) { + $tree = menu_tree_all_data($menu_name, NULL, TRUE); + $options[$menu_name .':0'] = '<'. $title .'>'; + _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid']); + } return $options; } /** * Recursive helper function for menu_parent_options(). */ -function _menu_parents_recurse($tree, $indent, &$options, $exclude) { +function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude) { foreach ($tree as $data) { if ($data['link']['mlid'] != $exclude) { $title = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, FALSE); if ($data['link']['hidden']) { $title .= ' ('. t('disabled') .')'; } - $options[$data['link']['mlid']] = $title; + $options[$menu_name .':'. $data['link']['mlid']] = $title; if ($data['below'] && $data['link']['depth'] < MENU_MAX_DEPTH - 1) { - _menu_parents_recurse($data['below'], $indent .'--', $options, $exclude); + _menu_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude); } } } @@ -556,7 +577,7 @@ function menu_nodeapi(&$node, $op) { case 'prepare': if (empty($node->menu)) { // Prepare the node for the edit form so that $node->menu always exists. - $menu_name = variable_get('menu_parent_items', 'navigation'); + $menu_name = variable_get('menu_default_node_menu', 'navigation'); $item = array(); if (isset($node->nid)) { $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = 'node/%d' AND menu_name = '%s' AND module = 'menu' ORDER BY mlid ASC", $node->nid, $menu_name)); @@ -602,7 +623,7 @@ function menu_form_alter(&$form, $form_s $form['menu']['#collapsed'] = TRUE; } - foreach (array('mlid', 'module', 'hidden', 'menu_name', 'has_children', 'customized', 'options', 'expanded', 'hidden') as $key) { + foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden') as $key) { $form['menu'][$key] = array('#type' => 'value', '#value' => $item[$key]); } @@ -613,13 +634,19 @@ function menu_form_alter(&$form, $form_s '#required' => FALSE, ); // Generate a list of possible parents (not including this item or descendants). - $options = menu_parent_options($item['menu_name'], $item); - $form['menu']['plid'] = array( + $options = menu_parent_options($item); + $default = $item['menu_name'] .':'. $item['plid']; + if (!isset($options[$default])) { + $default = 'navigation:0'; + } + $form['menu']['parent'] = array( '#type' => 'select', '#title' => t('Parent item'), - '#default_value' => $item['plid'], + '#default_value' => $default, '#options' => $options, ); + $form['#submit'][] = 'menu_node_form_submit'; + $form['menu']['weight'] = array( '#type' => 'weight', '#title' => t('Weight'), @@ -630,6 +657,13 @@ function menu_form_alter(&$form, $form_s } /** + * Decompose the selected menu parent option into the menu_name and plid. + */ +function menu_node_form_submit($form, &$form_state) { + list($form_state['values']['menu']['menu_name'], $form_state['values']['menu']['plid']) = explode(':', $form_state['values']['menu']['parent']); +} + +/** * Return an associative array of the custom menus names. * * @param $all @@ -656,16 +690,15 @@ function menu_get_menus($all = FALSE) { function menu_configure() { $form['intro'] = array( '#type' => 'item', - '#value' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. The following option limits the menus in which a new link may be added. E.g., this can be used to force new menu items to be created in the primary links menu or to hide admin menu items.'), + '#value' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. The following option sets the default menu in which a new link will be added.'), ); $authoring_options = menu_get_menus(TRUE); - - $form['menu_parent_items'] = array('#type' => 'select', - '#title' => t('Restrict parent items to'), - '#default_value' => variable_get('menu_parent_items', 0), + $form['menu_default_node_menu'] = array('#type' => 'select', + '#title' => t('Default menu for content'), + '#default_value' => variable_get('menu_default_node_menu', 'navigation'), '#options' => $authoring_options, - '#description' => t('Choose the menu to be made available in the content authoring form. Only this menu item and its children will be shown.'), + '#description' => t('Choose the menu to be the default in the menu options in the content authoring form.'), ); return system_settings_form($form);