You are here

function module_builder_menu_form in Module Builder 6

1 string reference to 'module_builder_menu_form'
module_builder_module_builder in ./module_builder.components.inc

File

./module_builder.components.inc, line 210

Code

function module_builder_menu_form(&$form_state, $values) {
  if (isset($form_state['storage']['menu_item_count']) && $form_state['storage']['menu_item_count'] > 1 && isset($form_state['storage']['items']) && !empty($form_state['storage']['items'])) {
    $menu_item_count = $form_state['storage']['menu_item_count'];
    $items = $form_state['storage']['items'];
  }
  elseif (isset($values->items)) {
    $menu_item_count = count($values->items);
    $items = $values->items;
  }
  else {
    $menu_item_count = 1;
  }
  $default_item = array(
    'title' => '',
    'path' => '',
    'type' => 'Normal',
    'callback' => '',
  );
  $form = array(
    '#cache' => FALSE,
    '#tree' => TRUE,
  );
  $form['items'] = array(
    '#type' => 'fieldset',
    '#title' => t('Menu items'),
    '#description' => t('If the module defines any menu items, fill out these values.'),
    '#collapsible' => FALSE,
    '#prefix' => '<div id="menu-items-wrapper">',
    '#suffix' => '</div>',
  );
  for ($delta = 0; $delta < $menu_item_count; $delta++) {
    if (!isset($items[$delta])) {
      $item = $default_item;
    }
    else {
      $item = $items[$delta] + $default_item;
    }
    $form['items'][$delta] = array(
      '#type' => 'fieldset',
      '#title' => t('Menu item'),
      // As an added bonus, change it to (!empty($item['title'])? $item['title'] : t('Menu item'))
      '#collapsible' => TRUE,
    );
    $form['items'][$delta]['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => t('The title of the menu item'),
      '#default_value' => $item['title'],
    );
    $form['items'][$delta]['path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path'),
      '#description' => t('The path of the menu item, such as admin/build/modules'),
      '#default_value' => $item['path'],
    );
    $form['items'][$delta]['type'] = array(
      '#type' => 'select',
      '#title' => t('Type'),
      '#multiple' => FALSE,
      '#options' => drupal_map_assoc(array(
        'Normal',
        'Tab',
        'Default tab',
        'Callback',
        'Suggested item',
        '#default_value' => $item['type'],
      )),
    );
    $form['items'][$delta]['callback'] = array(
      '#type' => 'textfield',
      '#title' => t('Callback'),
      '#description' => t('The title you enter here appears on the page.'),
      '#size' => 40,
      '#maxlength' => 255,
      '#default_value' => $item['callback'],
    );
  }
  $form['items']['new'] = array(
    '#type' => 'submit',
    '#value' => t('New menu item'),
    '#submit' => array(
      '_module_builder_menu_submit',
    ),
    '#ahah' => array(
      'wrapper' => 'menu-items-wrapper',
      'path' => 'module_builder/js',
    ),
  );
  return $form;
}