You are here

function menu_form_alter in Drupal 5

Same name and namespace in other branches
  1. 4 modules/menu.module \menu_form_alter()
  2. 6 modules/menu/menu.module \menu_form_alter()

Implementation of hook_form_alter(). Add menu item fields to the node form.

File

modules/menu/menu.module, line 174
Allows administrators to customize the site navigation menu.

Code

function menu_form_alter($form_id, &$form) {
  if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
    $item = array();
    if ($form['nid']['#value'] > 0) {
      $item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'node/%d' ORDER BY mid", $form['nid']['#value']));
      if (isset($form['#post']['menu']) && is_array($form['#post']['menu'])) {
        $item = !is_array($item) ? $form['#post']['menu'] : ($form['#post']['op'] == t('Preview') ? array_merge($item, $form['#post']['menu']) : array_merge($form['#post']['menu'], $item));
      }
    }
    $form['menu'] = array(
      '#type' => 'fieldset',
      '#title' => t('Menu settings'),
      '#access' => user_access('administer menu'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($item['title']),
      '#tree' => TRUE,
      '#weight' => 30,
    );
    $form['menu']['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#default_value' => $item['title'],
      '#description' => t('The name to display for this menu link.'),
    );
    $form['menu']['description'] = array(
      '#type' => 'textfield',
      '#title' => t('Description'),
      '#default_value' => $item['description'],
      '#description' => t('The description displayed when hovering over a menu item.'),
    );

    // Generate a list of possible parents.
    $options = menu_parent_options($item['mid'], variable_get('menu_parent_items', 0));
    $form['menu']['pid'] = array(
      '#type' => 'select',
      '#title' => t('Parent item'),
      '#default_value' => $item['pid'],
      '#options' => $options,
    );
    $form['menu']['path'] = array(
      '#type' => 'hidden',
      '#value' => $item['path'],
    );
    $form['menu']['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => $item['weight'],
      '#delta' => 10,
      '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'),
    );
    $form['menu']['mid'] = array(
      '#type' => 'hidden',
      '#value' => $item['mid'] ? $item['mid'] : 0,
    );
    $form['menu']['type'] = array(
      '#type' => 'hidden',
      '#value' => $item['type'] ? $item['type'] : MENU_CUSTOM_ITEM,
    );
    if ($item['mid'] > 0) {
      $form['menu']['delete'] = array(
        '#type' => 'checkbox',
        '#title' => t('Check to delete this menu item.'),
        '#default_value' => $item['delete'],
      );
      $form['menu']['advanced'] = array(
        '#type' => 'item',
        '#value' => t('You may also <a href="@edit">edit the advanced settings</a> for this menu item.', array(
          '@edit' => url("admin/build/menu/item/edit/{$item['mid']}"),
        )),
      );
    }
  }
}