You are here

function taxonomy_menu_term_set_form in Taxonomy menu 6.3

Implementation of hook_form(). Add Term Set form.

Parameters

$form_state:

$mgid:

1 string reference to 'taxonomy_menu_term_set_form'
taxonomy_menu_term_set_add in ./taxonomy_menu.admin.inc
Menu callback for adding a term set.

File

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

Code

function taxonomy_menu_term_set_form($form_state, $vocabs, $tsid = 0) {

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

  // If form_state['values'] is filled in then the form has alredy been submitted once
  // so pull out the

  //if tsid is passed then we are editing a term set.
  if ($tsid) {
    $term_set = taxonomy_menu_get_term_set($tsid);
    $form['tsid'] = array(
      '#type' => 'value',
      '#value' => $tsid,
    );
    $form_state['storage']['title'] = $term_set->name;
    $form_state['storage']['vid'] = $term_set->vid;
    $form_state['storage']['items'] = $term_set->items;

    // Extract the tids from the term object
    foreach ($term_set->items as $term) {
      $form_state['storage']['terms'][] = $term->tid;
    }
  }

  // If the form_values array if filled in then that instead
  if (isset($form_state['values'])) {
    $form_state['storage'] = $form_state['values'];
  }

  // Set the cache to true to create a $form_state cache on submit
  $form['#cache'] = TRUE;
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $form_state['storage']['title'],
    '#required' => TRUE,
  );

  //get a list of the vocabularies
  foreach ($vocabs as $vocab) {
    $vocab_items[$vocab->vid] = $vocab->name;
  }
  array_unshift($vocab_items, '-Select vocabulary-');

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

  //Select submit handler if js is not enabled.
  $form['vid_select_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update the Term Tree'),
    '#submit' => array(
      'taxonomy_menu_select_submit',
    ),
    '#attributes' => array(
      'class' => 'no-js',
    ),
  );
  $form['terms_wrapper'] = array(
    '#prefix' => '<div id="taxonomy-menu-tids">',
    '#suffix' => '</div>',
  );
  $form['terms_wrapper']['terms'] = array(
    '#type' => 'taxonomy_manager_tree',
    '#vid' => $form_state['storage']['vid'],
    '#title' => t('Select terms'),
    '#parent' => 0,
    '#multiple' => TRUE,
    '#add_term_info' => TRUE,
    '#default_value' => $form_state['storage']['terms'],
  );
  $form['sync_method'] = array(
    '#type' => 'select',
    '#title' => t('Sync Method'),
    '#required' => TRUE,
    '#options' => array(
      '-Select-',
    ),
    '#description' => t('TODO'),
  );
  $form['term_set_options'] = taxonomy_menu_get_options('TERM_SET', $tsid);

  //set the title of the group field set
  $form['term_set_options']['#title'] = t('Term Set Options');
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

  // Redirect back to the term_set list
  $form['#redirect'] = 'admin/build/taxonomy_menu/termset';
  return $form;
}