| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: menu.admin.inc,v 1.26.2.7 2010/06/02 12:56:20 goba Exp $ 3 4 /** 5 * @file 6 * Administrative page callbacks for menu module. 7 */ 8 9 /** 10 * Menu callback which shows an overview page of all the custom menus and their descriptions. 11 */ 12 function menu_overview_page() { 13 $result = db_query("SELECT * FROM {menu_custom} ORDER BY title"); 14 $content = array(); 15 while ($menu = db_fetch_array($result)) { 16 $menu['href'] = 'admin/build/menu-customize/'. $menu['menu_name']; 17 $menu['localized_options'] = array(); 18 $menu['description'] = filter_xss_admin($menu['description']); 19 $content[] = $menu; 20 } 21 return theme('admin_block_content', $content); 22 } 23 24 /** 25 * Form for editing an entire menu tree at once. 26 * 27 * Shows for one menu the menu items accessible to the current user and 28 * relevant operations. 29 */ 30 function menu_overview_form(&$form_state, $menu) { 31 global $menu_admin; 32 $sql = " 33 SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.* 34 FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path 35 WHERE ml.menu_name = '%s' 36 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC"; 37 $result = db_query($sql, $menu['menu_name']); 38 $tree = menu_tree_data($result); 39 $node_links = array(); 40 menu_tree_collect_node_links($tree, $node_links); 41 // We indicate that a menu administrator is running the menu access check. 42 $menu_admin = TRUE; 43 menu_tree_check_access($tree, $node_links); 44 $menu_admin = FALSE; 45 46 $form = _menu_overview_tree_form($tree); 47 $form['#menu'] = $menu; 48 if (element_children($form)) { 49 $form['submit'] = array( 50 '#type' => 'submit', 51 '#value' => t('Save configuration'), 52 ); 53 } 54 else { 55 $form['empty_menu'] = array('#value' => t('There are no menu items yet.')); 56 } 57 return $form; 58 } 59 60 /** 61 * Recursive helper function for menu_overview_form(). 62 */ 63 function _menu_overview_tree_form($tree) { 64 static $form = array('#tree' => TRUE); 65 foreach ($tree as $data) { 66 $title = ''; 67 $item = $data['link']; 68 // Don't show callbacks; these have $item['hidden'] < 0. 69 if ($item && $item['hidden'] >= 0) { 70 $mlid = 'mlid:'. $item['mlid']; 71 $form[$mlid]['#item'] = $item; 72 $form[$mlid]['#attributes'] = $item['hidden'] ? array('class' => 'menu-disabled') : array('class' => 'menu-enabled'); 73 $form[$mlid]['title']['#value'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' ('. t('disabled') .')' : ''); 74 $form[$mlid]['hidden'] = array( 75 '#type' => 'checkbox', 76 '#default_value' => !$item['hidden'], 77 ); 78 $form[$mlid]['expanded'] = array( 79 '#type' => 'checkbox', 80 '#default_value' => $item['expanded'], 81 ); 82 $form[$mlid]['weight'] = array( 83 '#type' => 'weight', 84 '#delta' => 50, 85 '#default_value' => isset($form_state[$mlid]['weight']) ? $form_state[$mlid]['weight'] : $item['weight'], 86 ); 87 $form[$mlid]['mlid'] = array( 88 '#type' => 'hidden', 89 '#value' => $item['mlid'], 90 ); 91 $form[$mlid]['plid'] = array( 92 '#type' => 'textfield', 93 '#default_value' => isset($form_state[$mlid]['plid']) ? $form_state[$mlid]['plid'] : $item['plid'], 94 '#size' => 6, 95 ); 96 // Build a list of operations. 97 $operations = array(); 98 $operations['edit'] = l(t('edit'), 'admin/build/menu/item/'. $item['mlid'] .'/edit'); 99 // Only items created by the menu module can be deleted. 100 if ($item['module'] == 'menu' || $item['updated'] == 1) { 101 $operations['delete'] = l(t('delete'), 'admin/build/menu/item/'. $item['mlid'] .'/delete'); 102 } 103 // Set the reset column. 104 elseif ($item['module'] == 'system' && $item['customized']) { 105 $operations['reset'] = l(t('reset'), 'admin/build/menu/item/'. $item['mlid'] .'/reset'); 106 } 107 108 $form[$mlid]['operations'] = array(); 109 foreach ($operations as $op => $value) { 110 $form[$mlid]['operations'][$op] = array('#value' => $value); 111 } 112 } 113 114 if ($data['below']) { 115 _menu_overview_tree_form($data['below']); 116 } 117 } 118 return $form; 119 } 120 121 /** 122 * Submit handler for the menu overview form. 123 * 124 * This function takes great care in saving parent items first, then items 125 * underneath them. Saving items in the incorrect order can break the menu tree. 126 * 127 * @see menu_overview_form() 128 */ 129 function menu_overview_form_submit($form, &$form_state) { 130 // When dealing with saving menu items, the order in which these items are 131 // saved is critical. If a changed child item is saved before its parent, 132 // the child item could be saved with an invalid path past its immediate 133 // parent. To prevent this, save items in the form in the same order they 134 // are sent by $_POST, ensuring parents are saved first, then their children. 135 // See http://drupal.org/node/181126#comment-632270 136 $order = array_flip(array_keys($form['#post'])); // Get the $_POST order. 137 $form = array_merge($order, $form); // Update our original form with the new order. 138 139 $updated_items = array(); 140 $fields = array('expanded', 'weight', 'plid'); 141 foreach (element_children($form) as $mlid) { 142 if (isset($form[$mlid]['#item'])) { 143 $element = $form[$mlid]; 144 // Update any fields that have changed in this menu item. 145 foreach ($fields as $field) { 146 if ($element[$field]['#value'] != $element[$field]['#default_value']) { 147 $element['#item'][$field] = $element[$field]['#value']; 148 $updated_items[$mlid] = $element['#item']; 149 } 150 } 151 // Hidden is a special case, the value needs to be reversed. 152 if ($element['hidden']['#value'] != $element['hidden']['#default_value']) { 153 $element['#item']['hidden'] = !$element['hidden']['#value']; 154 $updated_items[$mlid] = $element['#item']; 155 } 156 } 157 } 158 159 // Save all our changed items to the database. 160 foreach ($updated_items as $item) { 161 $item['customized'] = 1; 162 menu_link_save($item); 163 } 164 } 165 166 /** 167 * Theme the menu overview form into a table. 168 * 169 * @ingroup themeable 170 */ 171 function theme_menu_overview_form($form) { 172 drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1); 173 drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight'); 174 175 $header = array( 176 t('Menu item'), 177 array('data' => t('Enabled'), 'class' => 'checkbox'), 178 array('data' => t('Expanded'), 'class' => 'checkbox'), 179 t('Weight'), 180 array('data' => t('Operations'), 'colspan' => '3'), 181 ); 182 183 $rows = array(); 184 foreach (element_children($form) as $mlid) { 185 if (isset($form[$mlid]['hidden'])) { 186 $element = &$form[$mlid]; 187 // Build a list of operations. 188 $operations = array(); 189 foreach (element_children($element['operations']) as $op) { 190 $operations[] = drupal_render($element['operations'][$op]); 191 } 192 while (count($operations) < 2) { 193 $operations[] = ''; 194 } 195 196 // Add special classes to be used for tabledrag.js. 197 $element['plid']['#attributes']['class'] = 'menu-plid'; 198 $element['mlid']['#attributes']['class'] = 'menu-mlid'; 199 $element['weight']['#attributes']['class'] = 'menu-weight'; 200 201 // Change the parent field to a hidden. This allows any value but hides the field. 202 $element['plid']['#type'] = 'hidden'; 203 204 $row = array(); 205 $row[] = theme('indentation', $element['#item']['depth'] - 1) . drupal_render($element['title']); 206 $row[] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox'); 207 $row[] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox'); 208 $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']); 209 $row = array_merge($row, $operations); 210 211 $row = array_merge(array('data' => $row), $element['#attributes']); 212 $row['class'] = !empty($row['class']) ? $row['class'] .' draggable' : 'draggable'; 213 $rows[] = $row; 214 } 215 } 216 $output = ''; 217 if ($rows) { 218 $output .= theme('table', $header, $rows, array('id' => 'menu-overview')); 219 } 220 $output .= drupal_render($form); 221 return $output; 222 } 223 224 /** 225 * Menu callback; Build the menu link editing form. 226 */ 227 function menu_edit_item(&$form_state, $type, $item, $menu) { 228 229 $form['menu'] = array( 230 '#type' => 'fieldset', 231 '#title' => t('Menu settings'), 232 '#collapsible' => FALSE, 233 '#tree' => TRUE, 234 '#weight' => -2, 235 '#attributes' => array('class' => 'menu-item-form'), 236 '#item' => $item, 237 ); 238 if ($type == 'add' || empty($item)) { 239 // This is an add form, initialize the menu link. 240 $item = array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu['menu_name'], 'weight' => 0, 'link_path' => '', 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0); 241 } 242 foreach (array('link_path', 'mlid', 'module', 'has_children', 'options') as $key) { 243 $form['menu'][$key] = array('#type' => 'value', '#value' => $item[$key]); 244 } 245 // Any item created or edited via this interface is considered "customized". 246 $form['menu']['customized'] = array('#type' => 'value', '#value' => 1); 247 $form['menu']['original_item'] = array('#type' => 'value', '#value' => $item); 248 249 $path = $item['link_path']; 250 if (isset($item['options']['query'])) { 251 $path .= '?'. $item['options']['query']; 252 } 253 if (isset($item['options']['fragment'])) { 254 $path .= '#'. $item['options']['fragment']; 255 } 256 if ($item['module'] == 'menu') { 257 $form['menu']['link_path'] = array( 258 '#type' => 'textfield', 259 '#title' => t('Path'), 260 '#default_value' => $path, 261 '#description' => t('The path this menu item links to. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), 262 '#required' => TRUE, 263 ); 264 $form['delete'] = array( 265 '#type' => 'submit', 266 '#value' => t('Delete'), 267 '#access' => $item['mlid'], 268 '#submit' => array('menu_item_delete_submit'), 269 '#weight' => 10, 270 ); 271 } 272 else { 273 $form['menu']['_path'] = array( 274 '#type' => 'item', 275 '#title' => t('Path'), 276 '#description' => l($item['link_title'], $item['href'], $item['options']), 277 ); 278 } 279 $form['menu']['link_title'] = array('#type' => 'textfield', 280 '#title' => t('Menu link title'), 281 '#default_value' => $item['link_title'], 282 '#description' => t('The link text corresponding to this item that should appear in the menu.'), 283 '#required' => TRUE, 284 ); 285 $form['menu']['description'] = array( 286 '#type' => 'textarea', 287 '#title' => t('Description'), 288 '#default_value' => isset($item['options']['attributes']['title']) ? $item['options']['attributes']['title'] : '', 289 '#rows' => 1, 290 '#description' => t('The description displayed when hovering over a menu item.'), 291 ); 292 $form['menu']['enabled'] = array( 293 '#type' => 'checkbox', 294 '#title' => t('Enabled'), 295 '#default_value' => !$item['hidden'], 296 '#description' => t('Menu items that are not enabled will not be listed in any menu.'), 297 ); 298 $form['menu']['expanded'] = array( 299 '#type' => 'checkbox', 300 '#title' => t('Expanded'), 301 '#default_value' => $item['expanded'], 302 '#description' => t('If selected and this menu item has children, the menu will always appear expanded.'), 303 ); 304 305 // Generate a list of possible parents (not including this item or descendants). 306 $options = menu_parent_options(menu_get_menus(), $item); 307 $default = $item['menu_name'] .':'. $item['plid']; 308 if (!isset($options[$default])) { 309 $default = 'navigation:0'; 310 } 311 $form['menu']['parent'] = array( 312 '#type' => 'select', 313 '#title' => t('Parent item'), 314 '#default_value' => $default, 315 '#options' => $options, 316 '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth. Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)), 317 '#attributes' => array('class' => 'menu-title-select'), 318 ); 319 $form['menu']['weight'] = array( 320 '#type' => 'weight', 321 '#title' => t('Weight'), 322 '#delta' => 50, 323 '#default_value' => $item['weight'], 324 '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'), 325 ); 326 $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); 327 328 329 return $form; 330 } 331 332 /** 333 * Validate form values for a menu link being added or edited. 334 */ 335 function menu_edit_item_validate($form, &$form_state) { 336 $item = &$form_state['values']['menu']; 337 $normal_path = drupal_get_normal_path($item['link_path']); 338 if ($item['link_path'] != $normal_path) { 339 drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $item['link_path'], '%normal_path' => $normal_path))); 340 $item['link_path'] = $normal_path; 341 } 342 if (!menu_path_is_external($item['link_path'])) { 343 $parsed_link = parse_url($item['link_path']); 344 if (isset($parsed_link['query'])) { 345 $item['options']['query'] = $parsed_link['query']; 346 } 347 else { 348 // Use unset() rather than setting to empty string 349 // to avoid redundant serialized data being stored. 350 unset($item['options']['query']); 351 } 352 if (isset($parsed_link['fragment'])) { 353 $item['options']['fragment'] = $parsed_link['fragment']; 354 } 355 else { 356 unset($item['options']['fragment']); 357 } 358 if ($item['link_path'] != $parsed_link['path']) { 359 $item['link_path'] = $parsed_link['path']; 360 } 361 } 362 if (!trim($item['link_path']) || !menu_valid_path($item)) { 363 form_set_error('link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path']))); 364 } 365 } 366 367 /** 368 * Submit function for the delete button on the menu item editing form. 369 */ 370 function menu_item_delete_submit($form, &$form_state) { 371 $form_state['redirect'] = 'admin/build/menu/item/'. $form_state['values']['menu']['mlid'] .'/delete'; 372 } 373 374 /** 375 * Process menu and menu item add/edit form submissions. 376 */ 377 function menu_edit_item_submit($form, &$form_state) { 378 $item = &$form_state['values']['menu']; 379 380 // The value of "hidden" is the opposite of the value 381 // supplied by the "enabled" checkbox. 382 $item['hidden'] = (int) !$item['enabled']; 383 unset($item['enabled']); 384 385 $item['options']['attributes']['title'] = $item['description']; 386 list($item['menu_name'], $item['plid']) = explode(':', $item['parent']); 387 if (!menu_link_save($item)) { 388 drupal_set_message(t('There was an error saving the menu link.'), 'error'); 389 } 390 $form_state['redirect'] = 'admin/build/menu-customize/'. $item['menu_name']; 391 } 392 393 /** 394 * Menu callback; Build the form that handles the adding/editing of a custom menu. 395 */ 396 function menu_edit_menu(&$form_state, $type, $menu = array()) { 397 if ($type == 'edit') { 398 $form['menu_name'] = array('#type' => 'value', '#value' => $menu['menu_name']); 399 $form['#insert'] = FALSE; 400 $form['delete'] = array( 401 '#type' => 'submit', 402 '#value' => t('Delete'), 403 '#access' => !in_array($menu['menu_name'], menu_list_system_menus()), 404 '#submit' => array('menu_custom_delete_submit'), 405 '#weight' => 10, 406 ); 407 } 408 else { 409 $menu = array('menu_name' => '', 'title' => '', 'description' => ''); 410 $form['menu_name'] = array( 411 '#type' => 'textfield', 412 '#title' => t('Menu name'), 413 '#maxsize' => MENU_MAX_MENU_NAME_LENGTH_UI, 414 '#description' => t('The machine-readable name of this menu. This text will be used for constructing the URL of the <em>menu overview</em> page for this menu. This name must contain only lowercase letters, numbers, and hyphens, and must be unique.'), 415 '#required' => TRUE, 416 ); 417 $form['#insert'] = TRUE; 418 } 419 $form['#title'] = $menu['title']; 420 $form['title'] = array( 421 '#type' => 'textfield', 422 '#title' => t('Title'), 423 '#default_value' => $menu['title'], 424 '#required' => TRUE, 425 ); 426 $form['description'] = array( 427 '#type' => 'textarea', 428 '#title' => t('Description'), 429 '#default_value' => $menu['description'], 430 ); 431 $form['submit'] = array( 432 '#type' => 'submit', 433 '#value' => t('Save'), 434 ); 435 436 return $form; 437 } 438 439 /** 440 * Submit function for the 'Delete' button on the menu editing form. 441 */ 442 function menu_custom_delete_submit($form, &$form_state) { 443 $form_state['redirect'] = 'admin/build/menu-customize/'. $form_state['values']['menu_name'] .'/delete'; 444 } 445 446 /** 447 * Menu callback; check access and get a confirm form for deletion of a custom menu. 448 */ 449 function menu_delete_menu_page($menu) { 450 // System-defined menus may not be deleted. 451 if (in_array($menu['menu_name'], menu_list_system_menus())) { 452 drupal_access_denied(); 453 return; 454 } 455 return drupal_get_form('menu_delete_menu_confirm', $menu); 456 } 457 458 /** 459 * Build a confirm form for deletion of a custom menu. 460 */ 461 function menu_delete_menu_confirm(&$form_state, $menu) { 462 $form['#menu'] = $menu; 463 $caption = ''; 464 $num_links = db_result(db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = '%s'", $menu['menu_name'])); 465 if ($num_links) { 466 $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>'; 467 } 468 $caption .= '<p>'. t('This action cannot be undone.') .'</p>'; 469 return confirm_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')); 470 } 471 472 /** 473 * Delete a custom menu and all items in it. 474 */ 475 function menu_delete_menu_confirm_submit($form, &$form_state) { 476 $menu = $form['#menu']; 477 $form_state['redirect'] = 'admin/build/menu'; 478 // System-defined menus may not be deleted - only menus defined by this module. 479 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']))) { 480 return; 481 } 482 // Reset all the menu links defined by the system via hook_menu. 483 $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']); 484 while ($item = db_fetch_array($result)) { 485 menu_reset_item($item); 486 } 487 // Delete all links to the overview page for this menu. 488 $result = db_query("SELECT mlid FROM {menu_links} ml WHERE ml.link_path = '%s'", 'admin/build/menu-customize/'. $menu['menu_name']); 489 while ($m = db_fetch_array($result)) { 490 menu_link_delete($m['mlid']); 491 } 492 // Delete all the links in the menu and the menu from the list of custom menus. 493 db_query("DELETE FROM {menu_links} WHERE menu_name = '%s'", $menu['menu_name']); 494 db_query("DELETE FROM {menu_custom} WHERE menu_name = '%s'", $menu['menu_name']); 495 // Delete all the blocks for this menu. 496 db_query("DELETE FROM {blocks} WHERE module = 'menu' AND delta = '%s'", $menu['menu_name']); 497 db_query("DELETE FROM {blocks_roles} WHERE module = 'menu' AND delta = '%s'", $menu['menu_name']); 498 menu_cache_clear_all(); 499 cache_clear_all(); 500 $t_args = array('%title' => $menu['title']); 501 drupal_set_message(t('The custom menu %title has been deleted.', $t_args)); 502 watchdog('menu', 'Deleted custom menu %title and all its menu items.', $t_args, WATCHDOG_NOTICE); 503 } 504 505 /** 506 * Validates the human and machine-readable names when adding or editing a menu. 507 */ 508 function menu_edit_menu_validate($form, &$form_state) { 509 $item = $form_state['values']; 510 if (preg_match('/[^a-z0-9-]/', $item['menu_name'])) { 511 form_set_error('menu_name', t('The menu name may only consist of lowercase letters, numbers, and hyphens.')); 512 } 513 if (strlen($item['menu_name']) > MENU_MAX_MENU_NAME_LENGTH_UI) { 514 form_set_error('menu_name', format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters.")); 515 } 516 if ($form['#insert']) { 517 // We will add 'menu-' to the menu name to help avoid name-space conflicts. 518 $item['menu_name'] = 'menu-'. $item['menu_name']; 519 if (db_result(db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = '%s'", $item['menu_name'])) || 520 db_result(db_query_range("SELECT menu_name FROM {menu_links} WHERE menu_name = '%s'", $item['menu_name'], 0, 1))) { 521 form_set_error('menu_name', t('The menu already exists.')); 522 } 523 } 524 } 525 526 /** 527 * Submit function for adding or editing a custom menu. 528 */ 529 function menu_edit_menu_submit($form, &$form_state) { 530 $menu = $form_state['values']; 531 $path = 'admin/build/menu-customize/'; 532 if ($form['#insert']) { 533 // Add 'menu-' to the menu name to help avoid name-space conflicts. 534 $menu['menu_name'] = 'menu-'. $menu['menu_name']; 535 $link['link_title'] = $menu['title']; 536 $link['link_path'] = $path . $menu['menu_name']; 537 $link['router_path'] = $path .'%'; 538 $link['module'] = 'menu'; 539 $link['plid'] = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", 'admin/build/menu', 'system')); 540 menu_link_save($link); 541 db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menu['menu_name'], $menu['title'], $menu['description']); 542 } 543 else { 544 db_query("UPDATE {menu_custom} SET title = '%s', description = '%s' WHERE menu_name = '%s'", $menu['title'], $menu['description'], $menu['menu_name']); 545 $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", $path . $menu['menu_name']); 546 while ($m = db_fetch_array($result)) { 547 $link = menu_link_load($m['mlid']); 548 $link['link_title'] = $menu['title']; 549 menu_link_save($link); 550 } 551 } 552 $form_state['redirect'] = $path . $menu['menu_name']; 553 } 554 555 /** 556 * Menu callback; Check access and present a confirm form for deleting a menu link. 557 */ 558 function menu_item_delete_page($item) { 559 // Links defined via hook_menu may not be deleted. Updated items are an 560 // exception, as they can be broken. 561 if ($item['module'] == 'system' && !$item['updated']) { 562 drupal_access_denied(); 563 return; 564 } 565 return drupal_get_form('menu_item_delete_form', $item); 566 } 567 568 /** 569 * Build a confirm form for deletion of a single menu link. 570 */ 571 function menu_item_delete_form(&$form_state, $item) { 572 $form['#item'] = $item; 573 return confirm_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']); 574 } 575 576 /** 577 * Process menu delete form submissions. 578 */ 579 function menu_item_delete_form_submit($form, &$form_state) { 580 $item = $form['#item']; 581 menu_link_delete($item['mlid']); 582 $t_args = array('%title' => $item['link_title']); 583 drupal_set_message(t('The menu item %title has been deleted.', $t_args)); 584 watchdog('menu', 'Deleted menu item %title.', $t_args, WATCHDOG_NOTICE); 585 $form_state['redirect'] = 'admin/build/menu-customize/'. $item['menu_name']; 586 } 587 588 /** 589 * Menu callback; reset a single modified item. 590 */ 591 function menu_reset_item_confirm(&$form_state, $item) { 592 $form['item'] = array('#type' => 'value', '#value' => $item); 593 return confirm_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')); 594 } 595 596 /** 597 * Process menu reset item form submissions. 598 */ 599 function menu_reset_item_confirm_submit($form, &$form_state) { 600 $item = $form_state['values']['item']; 601 $new_item = menu_reset_item($item); 602 drupal_set_message(t('The menu item was reset to its default settings.')); 603 $form_state['redirect'] = 'admin/build/menu-customize/'. $new_item['menu_name']; 604 } 605 606 /** 607 * Menu callback; Build the form presenting menu configuration options. 608 */ 609 function menu_configure() { 610 $form['intro'] = array( 611 '#type' => 'item', 612 '#value' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. The following option sets the default menu in which a new link will be added.'), 613 ); 614 615 $menu_options = menu_get_menus(); 616 $form['menu_default_node_menu'] = array( 617 '#type' => 'select', 618 '#title' => t('Default menu for content'), 619 '#default_value' => variable_get('menu_default_node_menu', 'primary-links'), 620 '#options' => $menu_options, 621 '#description' => t('Choose the menu to be the default in the menu options in the content authoring form.'), 622 ); 623 624 $primary = variable_get('menu_primary_links_source', 'primary-links'); 625 $primary_options = array_merge($menu_options, array('' => t('No primary links'))); 626 $form['menu_primary_links_source'] = array( 627 '#type' => 'select', 628 '#title' => t('Source for the primary links'), 629 '#default_value' => $primary, 630 '#options' => $primary_options, 631 '#tree' => FALSE, 632 '#description' => t('Select what should be displayed as the primary links.'), 633 ); 634 635 $secondary_options = array_merge($menu_options, array('' => t('No secondary links'))); 636 $form["menu_secondary_links_source"] = array( 637 '#type' => 'select', 638 '#title' => t('Source for the secondary links'), 639 '#default_value' => variable_get('menu_secondary_links_source', 'secondary-links'), 640 '#options' => $secondary_options, 641 '#tree' => FALSE, 642 '#description' => t('Select what should be displayed as the secondary links. You can choose the same menu for secondary links as for primary links (currently %primary). If you do this, the children of the active primary menu link will be displayed as secondary links.', array('%primary' => $primary_options[$primary])), 643 ); 644 645 return system_settings_form($form); 646 } 647
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |