--- modules/menu/menu.module 2010-09-24 02:37:43.000000000 +0200 +++ modules/menu/menu.module 2010-10-29 15:51:47.798000000 +0200 @@ -316,6 +316,9 @@ function menu_delete($menu) { * @param $item * The menu item or the node type for which to generate a list of parents. * If $item['mlid'] == 0 then the complete tree is returned. + * @param $type + * The node type for which to generate a list of parents. + * If $item itself is a node type then $type is ignored. * @return * An array of menu link titles keyed on the a string containing the menu name * and mlid. The list excludes the given item and its children. @@ -323,7 +326,7 @@ function menu_delete($menu) { * @todo This has to be turned into a #process form element callback. The * 'menu_override_parent_selector' variable is entirely superfluous. */ -function menu_parent_options($menus, $item) { +function menu_parent_options($menus, $item, $type = '') { // The menu_links table can be practically any size and we need a way to // allow contrib modules to provide more scalable pattern choosers. // hook_form_alter is too late in itself because all the possible parents are @@ -333,18 +336,18 @@ function menu_parent_options($menus, $it } $available_menus = array(); - if (is_array($item)) { - // If $item is an array fill it with all menus given to this function. + if (!is_array($item)) { + $type = $item; + $item = array('mlid' => 0); + } + if (empty($type)) { $available_menus = $menus; } else { - // If $item is a node type, get all available menus for this type and - // prepare a dummy menu item for _menu_parent_depth_limit(). $type_menus = variable_get('menu_options_' . $item, array('main-menu' => 'main-menu')); foreach ($type_menus as $menu) { $available_menus[$menu] = $menu; } - $item = array('mlid' => 0); } return _menu_get_options($menus, $available_menus, $item); @@ -589,15 +592,15 @@ function _menu_parent_depth_limit($item) * @see menu_node_submit() */ function menu_form_node_form_alter(&$form, $form_state) { - // Generate a list of possible parents. + // Generate a list of possible parents (not including this link or descendants). // @todo This must be handled in a #process handler. + $link = $form['#node']->menu; $type = $form['#node']->type; - $options = menu_parent_options(menu_get_menus(), $type); + $options = menu_parent_options(menu_get_menus(), ($link['mlid'] ? $link : $type), $type); // If no possible parent menu items were found, there is nothing to display. if (empty($options)) { return; } - $link = $form['#node']->menu; $form['menu'] = array( '#type' => 'fieldset', @@ -648,9 +651,9 @@ function menu_form_node_form_alter(&$for ); $default = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : variable_get('menu_parent_' . $type, 'main-menu:0')); - // @todo This will fail with the new selective menus per content type. + // @todo If the current parent menu item is not present in options, user should not be allowed to access menu link settings. if (!isset($options[$default])) { - $default = 'navigation:0'; + $default = reset(array_keys($options)); } $form['menu']['link']['parent'] = array( '#type' => 'select',