$num_links=db_result(db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = '%s'",$menu['menu_name']));
if($num_links){
$caption.='<p>'.format_plural($num_links,'<strong>Warning:</strong> There is currently 1 menu item in %title. It will be deleted (system-defined items will be reset).','<strong>Warning:</strong> There are currently @count menu items in %title. They will be deleted (system-defined items will be reset).',array('%title'=>$menu['title'])).'</p>';
}
$caption.='<p>'.t('This action cannot be undone.').'</p>';
returnconfirm_form($form,t('Are you sure you want to delete the custom menu %title?',array('%title'=>$menu['title'])),'admin/build/menu-customize/'.$menu['menu_name'],$caption,t('Delete'));
// System-defined menus may not be deleted - only menus defined by this module.
if(in_array($menu['menu_name'],menu_list_system_menus())||!db_result(db_query("SELECT COUNT(*) FROM {menu_custom} WHERE menu_name = '%s'",$menu['menu_name']))){
return;
}
// Reset all the menu links defined by the system via hook_menu.
$result=db_query("SELECT * FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = '%s' AND ml.module = 'system' ORDER BY m.number_parts ASC",$menu['menu_name']);
while($item=db_fetch_array($result)){
menu_reset_item($item);
}
// Delete all links to the overview page for this menu.
$result=db_query("SELECT mlid FROM {menu_links} ml WHERE ml.link_path = '%s'",'admin/build/menu-customize/'.$menu['menu_name']);
while($m=db_fetch_array($result)){
menu_link_delete($m['mlid']);
}
// Delete all the links in the menu and the menu from the list of custom menus.
db_query("DELETE FROM {menu_links} WHERE menu_name = '%s'",$menu['menu_name']);
db_query("DELETE FROM {menu_custom} WHERE menu_name = '%s'",$menu['menu_name']);
// Delete all the blocks for this menu.
db_query("DELETE FROM {blocks} WHERE module = 'menu' AND delta = '%s'",$menu['menu_name']);
db_query("DELETE FROM {blocks_roles} WHERE module = 'menu' AND delta = '%s'",$menu['menu_name']);
menu_cache_clear_all();
cache_clear_all();
$t_args=array('%title'=>$menu['title']);
drupal_set_message(t('The custom menu %title has been deleted.',$t_args));
watchdog('menu','Deleted custom menu %title and all its menu items.',$t_args,WATCHDOG_NOTICE);
}
/**
* Validates the human and machine-readable names when adding or editing a menu.
*/
...
...
@@ -484,12 +563,21 @@ function menu_edit_menu_submit($form, &$form_state) {
}
/**
* Menu callback; Build a confirm form for deletion of a single menu link.
* Menu callback; Check access and present a confirm form for deleting a menu link.
returnconfirm_form($form,t('Are you sure you want to delete the custom menu item %item?',array('%item'=>$item['link_title'])),'admin/build/menu-customize/'.$item['menu_name']);
}
...
...
@@ -509,7 +597,7 @@ function menu_item_delete_form_submit($form, &$form_state) {
returnconfirm_form($form,t('Are you sure you want to reset the item %item to its default values?',array('%item'=>$item['link_title'])),'admin/build/menu-customize/'.$item['menu_name'],t('Any customizations will be lost. This action cannot be undone.'),t('Reset'));
}
...
...
@@ -517,16 +605,24 @@ function menu_reset_item(&$form_state, $item) {