You are here

function taxonomy_menu_group_form in Taxonomy menu 6.3

Implementation of hook_form().

1 string reference to 'taxonomy_menu_group_form'
taxonomy_menu_menu in ./taxonomy_menu.module
Implementation of hook_menu().

File

./taxonomy_menu.admin.inc, line 124
admin section for taxonomy menu

Code

function taxonomy_menu_group_form($form_state, $mgid = 0) {

  // Add termsets list page to the breadcrumb trail for easier navication
  $breadcrumb = drupal_get_breadcrumb();
  $breadcrumb[] = l(t('Menu Groups'), 'admin/build/taxonomy_menu');
  drupal_set_breadcrumb($breadcrumb);

  // choose a menu to add link items to.
  $menu_items = menu_parent_options(menu_get_menus(), NULL);
  if ($mgid) {
    $menu_group = taxonomy_menu_get_group($mgid);
    $form_state['storage']['menu_group_name'] = $menu_group->name;
    $form_state['storage']['parent_menu_item'] = $menu_group->parent_menu;
    $form_state['storage']['path'] = $menu_group->path;
    $form_state['storage']['mgid'] = $mgid;
    $form_state['storage']['items'] = $menu_group->items;
  }

  //menu group name
  $form['menu_group_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Menu Group Name'),
    '#default_value' => $form_state['storage']['menu_group_name'],
    '#required' => TRUE,
  );

  //select the parent menu item
  $form['parent_menu_item'] = array(
    '#type' => 'select',
    '#title' => t('Parent Menu Item'),
    '#default_value' => $form_state['storage']['parent_menu_item'],
    '#options' => $menu_items,
    '#required' => TRUE,
    '#description' => t('The Parent Menu Item that the Menu Link will be built under.'),
  );

  //set the path type for the menu group
  $form['path'] = array(
    '#type' => 'select',
    '#title' => t('Path Type'),
    '#default_value' => $form_state['storage']['path'],
    '#options' => taxonomy_menu_get_paths(),
    '#required' => TRUE,
    '#ahah' => array(
      'event' => 'change',
      'method' => 'replace',
      'path' => 'taxonomy_menu/ahah/path',
      'wrapper' => 'taxonomy-menu-path-options',
      'effect' => 'fade',
    ),
  );

  //Select submit handler if js is not enabled.
  $form['vid_select_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update the Path Type'),
    '#submit' => array(
      'taxonomy_menu_select_submit',
    ),
    '#attributes' => array(
      'class' => 'no-js',
    ),
  );

  //get the path options
  $form['path_options'] = taxonomy_menu_get_options('PATH', $form_state['storage']['path']);

  //set the title of the field set
  $form['path_options']['#title'] = t('Path Options');
  $form['path_options']['#prefix'] = '<div id = "taxonomy-menu-path-options">';
  $form['path_options']['#suffix'] = '</div>';
  $form['path_options']['#collapsed'] = TRUE;
  $form['term_sets'] = array(
    '#prefix' => '<div id="taxonomy-menu-term-sets">',
    '#suffix' => '</div>',
    '#theme' => 'taxonomy_menu_term_set_table',
  );

  // List of Term Sets
  $term_sets = taxonomy_menu_get_term_sets_by_group($form_state['storage']['mgid']);
  foreach ($term_sets as $term_set) {
    $form['term_sets']['list'][$term_set->tsid]['name'] = array(
      '#value' => t($term_set->name),
    );
    $form['term_sets']['list'][$term_set->tsid]['vocab'] = array(
      '#value' => t($term_set->vocab_name),
    );
    $form['term_sets']['list'][$term_set->tsid]['parent'] = array(
      '#value' => t($term_set->parent->name),
    );
    $form['term_sets']['list'][$term_set->tsid]['remove'] = array(
      '#type' => 'submit',
      '#value' => t('Remove'),
      '#submit' => 'taxonomy_menu_group_remove_term_set_submit',
      '#ahah' => array(
        'path' => 'taxonomy_menu/ahah/term_sets_remove/' . $form_state['storage']['mgid'] . '/' . $term_set->tsid,
        'wrapper' => 'taxonomy-menu-term-sets',
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
  }

  // Pass the mgid to to term set theme
  $form['term_sets']['mgid'] = array(
    '#type' => 'value',
    '#value' => $form_state['storage']['mgid'],
  );

  // Only render the term set add if we are editing.
  if ($form_state['storage']['mgid']) {

    // feildset containing the list of term sets and the add button
    $form['term_sets']['term_set_add'] = array(
      '#type' => 'fieldset',
      '#title' => t('Assoicate Term Set to Menu Group'),
      '#tree' => FALSE,
      '#theme' => 'taxonomy_menu_group_term_set_add',
    );
    $form['term_sets']['term_set_add']['term_set'] = array(
      '#type' => 'select',
      '#title' => t('Term Set'),
      '#options' => _taxonomy_menu_get_term_sets_options($form_state['storage']['mgid']),
    );
    $form['term_sets']['term_set_add']['term_set_parent'] = array(
      '#type' => 'select',
      '#title' => t('Parent Term Set Item'),
      '#options' => _taxonomy_menu_get_term_set_parent_item_options($form_state['storage']['items']),
    );
    $form['term_sets']['term_set_add']['term_set_more'] = array(
      '#type' => 'submit',
      '#value' => t('Associate'),
      '#submit' => array(
        'taxonomy_menu_group_term_submit',
      ),
      '#ahah' => array(
        'path' => 'taxonomy_menu/ahah/term_sets',
        'wrapper' => 'taxonomy-menu-term-sets',
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
  }

  //get the group options
  $form['group_options'] = taxonomy_menu_get_options('GROUP', $form_state['storage']['mgid']);

  //set the title of the group field set
  $form['group_options']['#title'] = t('Group Options');
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}