[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/modules/menu/ -> menu.admin.inc (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7