? .project
? modules/.DS_Store
? sites/all/themes/.DS_Store
? sites/default/.DS_Store
Index: modules/menu/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v
retrieving revision 1.194
diff -u -p -r1.194 menu.module
--- modules/menu/menu.module	5 Jul 2009 18:00:09 -0000	1.194
+++ modules/menu/menu.module	17 Jul 2009 20:33:56 -0000
@@ -199,7 +199,7 @@ function menu_load($menu_name) {
  * @param $menus
  *   An array of menu names and titles, such as from menu_get_menus().
  * @param $item
- *   The menu item for which to generate a list of parents.
+ *   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.
  * @return
  *   An array of menu link titles keyed on the a string containing the menu name
@@ -213,6 +213,21 @@ function menu_parent_options($menus, $it
   if (variable_get('menu_override_parent_selector', FALSE)) {
     return array();
   }
+
+  $available_menus = array();
+  if (is_array($item)) {
+    // If $item is an array fill it with all menus given to this function.
+    $available_menus = $menus;
+  }
+  else {
+    // If $item is a node type, get all available menus for this type and prepare a dummy menu item.
+    $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);
+  }
+
   // If the item has children, there is an added limit to the depth of valid parents.
   if (isset($item['parent_depth_limit'])) {
     $limit = $item['parent_depth_limit'];
@@ -221,10 +236,13 @@ function menu_parent_options($menus, $it
     $limit = _menu_parent_depth_limit($item);
   }
 
+  $options = array();
   foreach ($menus as $menu_name => $title) {
-    $tree = menu_tree_all_data($menu_name, NULL);
-    $options[$menu_name . ':0'] = '<' . $title . '>';
-    _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);
+    if (isset($available_menus[$menu_name])) {
+      $tree = menu_tree_all_data($menu_name, NULL);
+      $options[$menu_name . ':0'] = '<' . $title . '>';
+      _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);
+    }
   }
   return $options;
 }
@@ -392,6 +410,15 @@ function _menu_parent_depth_limit($item)
  */
 function menu_form_alter(&$form, $form_state, $form_id) {
   if (!empty($form['#node_edit_form'])) {
+    // Generate a list of possible parents.
+    $type = $form['#node']->type;
+    $options = menu_parent_options(menu_get_menus(), $type);
+    if (count($options) == 0) {
+    	// No possible parent menu items found so there is no need to display the
+    	// menu options.
+      return;
+    }
+    
     // Note - doing this to make sure the delete checkbox stays in the form.
     $form['#cache'] = TRUE;
 
@@ -431,9 +458,8 @@ function menu_form_alter(&$form, $form_s
       '#description' => t('The link text corresponding to this item that should appear in the menu. Leave blank if you do not wish to add this post to the menu.'),
       '#required' => FALSE,
     );
-    // Generate a list of possible parents (not including this item or descendants).
-    $options = menu_parent_options(menu_get_menus(), $item);
-    $default = $item['menu_name'] . ':' . $item['plid'];
+
+    $default = ($item['mlid'] ? $item['menu_name'] . ':' . $item['plid'] : variable_get('menu_parent_' . $type, 'main-menu:0'));
     if (!isset($options[$default])) {
       $default = 'main-menu:0';
     }
@@ -458,6 +484,37 @@ function menu_form_alter(&$form, $form_s
 }
 
 /**
+ * Implement hook_form_FORM_ID_alter() for the node type form. 
+ * Adds menu options to the node type form.
+ */
+function menu_form_node_type_form_alter(&$form, $form_state) {
+  $menu_options = menu_get_menus();
+  $type = $form['#node_type'];
+  $form['menu'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Menu settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['menu']['menu_options'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Available menus'),
+    '#default_value' => variable_get('menu_options_' . $type->type, array('main-menu' => 'main-menu')),
+    '#options' => $menu_options,
+    '#description' => t('Menus which should appear in the <em>add menu item</em> section.'),
+  );
+  $options = menu_parent_options(menu_get_menus(), array('mlid' => 0));
+  $form['menu']['menu_parent'] = array(
+    '#type' => 'select',
+    '#title' => t('Default parent item'),
+    '#default_value' => variable_get('menu_parent_' . $type->type, 'main-menu:0'),
+    '#options' => $options,
+    '#description' => t('Choose the menu item to be default for the <em>menu settings</em> in the content authoring form.'),
+    '#attributes' => array('class' => 'menu-title-select'),
+  );
+}
+
+/**
  * Decompose the selected menu parent option into the menu_name and plid.
  */
 function menu_node_form_submit($form, &$form_state) {
