? .project
? sites/all/themes/.DS_Store
? sites/default/.DS_Store
? sites/default/files
? sites/default/settings.php
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 12:07:46 -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'];
@@ -222,9 +237,11 @@ function menu_parent_options($menus, $it
}
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;
}
@@ -432,8 +449,9 @@ 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(menu_get_menus(), $item);
- $default = $item['menu_name'] . ':' . $item['plid'];
+ $type = $form['#node']->type;
+ $options = menu_parent_options(menu_get_menus(), $type);
+ $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 +476,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 add menu item 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 menu settings 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) {