Index: modules/menu/menu.install =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.install,v retrieving revision 1.19 diff -u -r1.19 menu.install --- modules/menu/menu.install 20 Jul 2009 18:51:33 -0000 1.19 +++ modules/menu/menu.install 27 Aug 2009 06:08:09 -0000 @@ -21,9 +21,12 @@ 'secondary-menu' => 'The Secondary menu is the default source for the Secondary links which are often used for legal notices, contact details, and other navigation items that play a lesser role than the Main links.', ); $t = get_t(); - $query = db_insert('menu_custom')->fields(array('menu_name', 'title', 'description')); foreach ($system_menus as $menu_name => $title) { - $query->values(array('menu_name' => $menu_name, 'title' => $t($title), 'description' => $t($descriptions[$menu_name])))->execute(); + menu_custom_save(array( + 'menu_name' => $menu_name, + 'title' => $t($title), + 'description' => $t($descriptions[$menu_name]), + )); } } Index: modules/menu/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v retrieving revision 1.200 diff -u -r1.200 menu.module --- modules/menu/menu.module 24 Aug 2009 00:14:21 -0000 1.200 +++ modules/menu/menu.module 27 Aug 2009 06:08:13 -0000 @@ -204,6 +204,44 @@ } /** + * Save a custom menu. + * + * @param $custom_menu + * The custom menu object or array to be saved. + * @return + * Status constant indicating if role was created or updated. + * Failure to write the user role record will return FALSE. Otherwise. + * SAVED_NEW or SAVED_UPDATED is returned depending on the operation + * performed. + */ +function menu_custom_save($custom_menu) { + $custom_menu = (object) $custom_menu; + db_merge('menu_custom') + ->key(array('menu_name' => $custom_menu->menu_name)) + ->fields(array( + 'title' => $custom_menu->title, + 'description' => $custom_menu->description, + )) + ->execute(); +} + +/** + * Delete custom menu from the database + * + * @param $menu_name + * The name of the custom menu to be deleted.. + */ +function menu_custom_delete($menu_name) { + // Delete all the links in the menu and the menu from the list of custom menus. + db_delete('menu_custom') + ->condition('menu_name', $menu_name) + ->execute(); + db_delete('menu_links') + ->condition('menu_name', $menu_name) + ->execute(); +} + +/** * Return a list of menu items that are valid possible parents for the given menu item. * * @param $menus Index: modules/menu/menu.test =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.test,v retrieving revision 1.20 diff -u -r1.20 menu.test --- modules/menu/menu.test 21 Aug 2009 14:27:44 -0000 1.20 +++ modules/menu/menu.test 27 Aug 2009 06:08:15 -0000 @@ -87,6 +87,34 @@ $this->menu = $this->addCustomMenu(); $this->doMenuTests($this->menu['menu_name']); $this->addInvalidMenuLink($this->menu['menu_name']); + $this->addCustomMenuApi(); + } + + /** + * Add custom menu using API. + */ + function addCustomMenuApi() { + // Add a new custom menu. + $menu_name = substr(md5($this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI); + $title = $this->randomName(16); + + $menu = array( + 'menu_name' => $menu_name, + 'title' => $title, + 'description' => 'Description text', + ); + menu_custom_save($menu); + + // Assert the menu. + $this->drupalGet('admin/structure/menu-customize/' . $menu_name . '/edit'); + $this->assertText($title, t('Custom menu was added.')); + + // Edit the menu. + $new_title = $this->randomName(16); + $menu['title'] = $new_title; + menu_custom_save($menu); + $this->drupalGet('admin/structure/menu-customize/' . $menu_name . '/edit'); + $this->assertText($new_title, t('Custom menu was edited.')); } /** Index: modules/menu/menu.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.admin.inc,v retrieving revision 1.56 diff -u -r1.56 menu.admin.inc --- modules/menu/menu.admin.inc 24 Aug 2009 01:49:41 -0000 1.56 +++ modules/menu/menu.admin.inc 27 Aug 2009 06:08:09 -0000 @@ -527,13 +527,10 @@ foreach ($result as $m) { menu_link_delete($m['mlid']); } + // Delete all the links in the menu and the menu from the list of custom menus. - db_delete('menu_links') - ->condition('menu_name', $menu['menu_name']) - ->execute(); - db_delete('menu_custom') - ->condition('menu_name', $menu['menu_name']) - ->execute(); + menu_custom_delete($menu['menu_name']); + // Delete all the blocks for this menu. if (module_exists('block')) { db_delete('block') @@ -595,22 +592,10 @@ ->fetchField(); menu_link_save($link); - db_insert('menu_custom') - ->fields(array( - 'menu_name' => $menu['menu_name'], - 'title' => $menu['title'], - 'description' => $menu['description'], - )) - ->execute(); + menu_custom_save($menu); } else { - db_update('menu_custom') - ->fields(array( - 'title' => $menu['title'], - 'description' => $menu['description'], - )) - ->condition('menu_name', $menu['menu_name']) - ->execute(); + menu_custom_save($menu); $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path", array(':path' => $path . $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC)); foreach ($result as $m) { $link = menu_link_load($m['mlid']); Index: modules/toolbar/toolbar.install =================================================================== RCS file: /cvs/drupal/drupal/modules/toolbar/toolbar.install,v retrieving revision 1.3 diff -u -r1.3 toolbar.install --- modules/toolbar/toolbar.install 30 Jul 2009 19:24:21 -0000 1.3 +++ modules/toolbar/toolbar.install 27 Aug 2009 06:08:23 -0000 @@ -14,14 +14,11 @@ */ function toolbar_install() { $t = get_t(); - $query = db_insert('menu_custom') - ->fields(array( - 'menu_name' => 'admin_shortcuts', - 'title' => $t('Administration shortcuts'), - 'description' => $t('The Admininstration shortcuts menu contains commonly used links for administrative tasks.') - )) - ->execute(); - + menu_custom_save(array( + 'menu_name' => 'admin_shortcuts', + 'title' => $t('Administration shortcuts'), + 'description' => $t('The Admininstration shortcuts menu contains commonly used links for administrative tasks.') + )); // Add starter convenience shortcuts. menu_rebuild(); $items = array( Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.341 diff -u -r1.341 menu.inc --- includes/menu.inc 24 Aug 2009 01:49:41 -0000 1.341 +++ includes/menu.inc 27 Aug 2009 06:08:05 -0000 @@ -1384,7 +1384,13 @@ * Return an array containing the names of system-defined (default) menus. */ function menu_list_system_menus() { - return array('navigation' => 'Navigation', 'management' => 'Management', 'user-menu' => 'User menu', 'main-menu' => 'Main menu', 'secondary-menu' => 'Secondary menu'); + return array( + 'navigation' => 'Navigation', + 'management' => 'Management', + 'user-menu' => 'User menu', + 'main-menu' => 'Main menu', + 'secondary-menu' => 'Secondary menu' + ); } /**