You are here

function taxonomy_manager_form in Taxonomy Manager 6

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_form()
  2. 6.2 taxonomy_manager.admin.inc \taxonomy_manager_form()
  3. 7 taxonomy_manager.admin.inc \taxonomy_manager_form()

defines forms for taxonomy manager interface

Parameters

$vid vocabulary id:

$tid a term id, if not 0, displays term editing from for given tid on right side:

$search_string a string to filter root level terms:

3 string references to 'taxonomy_manager_form'
taxonomy_manager_menu in ./taxonomy_manager.module
Implementation of hook_menu
taxonomy_manager_tree_build_siblings_form in ./taxonomy_manager.module
callback for generating and rendering next siblings terms form (AHAH)
taxonomy_manager_update_term_data_form in ./taxonomy_manager.admin.inc
menu callback for displaying term data form

File

./taxonomy_manager.admin.inc, line 31

Code

function taxonomy_manager_form(&$form_state, $vid, $tid = 0, $filter = NULL) {

  // Check for confirmation forms.
  if (isset($form_state['confirm_delete'])) {
    return taxonomy_manager_term_confirm_delete($form_state, $vid);
  }
  $module_path = drupal_get_path('module', 'taxonomy_manager') . '/';
  drupal_add_css($module_path . 'css/taxonomy_manager.css');
  drupal_add_js($module_path . 'js/hideForm.js');
  drupal_add_js($module_path . 'js/updateWeight.js');
  drupal_add_js($module_path . 'js/termData.js');
  drupal_add_js('misc/textarea.js');

  //because of term data form wich gets dynamically loaded
  drupal_add_js(array(
    'termData' => array(
      'url' => url("admin/content/taxonomy_manager/termdata/edit/" . $vid),
      'tid' => $tid,
      'term_url' => url('admin/content/taxonomy_manager/termdata/' . $vid),
    ),
  ), 'setting');
  drupal_add_js(array(
    'updateWeight' => array(
      'up' => 'edit-weight-up',
      'down' => 'edit-weight-down',
      'url' => url('admin/content/taxonomy_manager/weight/' . $vid),
      'disable_mouseover' => variable_get('taxonomy_manager_disable_mouseover', 0),
    ),
  ), 'setting');
  drupal_add_js(array(
    'TMAjaxThrobber' => array(
      'add' => TRUE,
    ),
  ), 'setting');
  $form = array();
  $voc = taxonomy_vocabulary_load($vid);
  drupal_set_title(t("Taxonomy Manager - %voc_name", array(
    "%voc_name" => $voc->name,
  )));
  if (!is_numeric($voc->vid)) {
    $text = t('No vocabulary with this ID available!. ');
    $text .= t('Check this !link_list for available vocabularies or !link_create a new one', array(
      '!link_list' => l('list', 'admin/content/taxonomy_manager'),
      '!link_create' => l('create', 'admin/content/taxonomy/add/vocabulary'),
    ));
    $form['text'] = array(
      '#value' => $text,
    );
    return $form;
  }
  $form['vid'] = array(
    '#type' => 'value',
    "#value" => $vid,
  );
  if (_taxonomy_manager_voc_is_empty($vid)) {
    $text = t('No terms available');
    $form['text'] = array(
      '#value' => $text,
    );
    $form += taxonomy_manager_add_form($voc, false);
    return $form;
  }
  $form['#cache'] = TRUE;
  $form['taxonomy']['#tree'] = TRUE;
  $form['taxonomy']['manager'] = array(
    '#type' => 'fieldset',
    '#title' => check_plain($voc->name),
    '#weight' => 10,
    '#tree' => TRUE,
  );
  $form['taxonomy']['manager']['markup'] = array(
    '#value' => '<div id="taxonomy-manager-tree-size">' . theme("image", $module_path . "images/grippie.png", "decrease tree window size", NULL, array(
      'class' => "div-grippie",
    )) . '</div>',
  );
  $form['taxonomy']['manager']['tree'] = array(
    '#type' => 'taxonomy_manager_tree',
    '#vid' => $vid,
    '#pager' => TRUE,
    '#search_string' => $tid ? NULL : $filter,
  );
  $search_description = t("You can search directly for exisiting terms. \n      If your input doesn't match an existing term, it will be used for filtering root level terms (useful for non-hierarchical vocabularies).");
  $form['search'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'id' => 'taxonomy-manager-search',
    ),
    '#title' => t('Search'),
    '#description' => $search_description,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $form['search']['field'] = array(
    '#type' => 'textfield',
    '#title' => t('Search String'),
    '#autocomplete_path' => 'taxonomy_manager/autocomplete/' . $voc->vid,
    '#prefix' => '<div id="edit-find-field">',
    '#suffix' => '</div>',
  );
  $form['search']['button'] = array(
    '#type' => 'submit',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons search',
    ),
    '#value' => t('Search'),
    '#suffix' => '<div class="clear"></div>',
  );
  $form['toolbar'] = array(
    '#type' => 'fieldset',
    '#title' => t('Toolbar'),
    '#attributes' => array(
      'id' => 'taxonomy-manager-toolbar',
    ),
  );
  $form['toolbar']['weight_up'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons',
    ),
    '#value' => t('Up'),
    '#theme' => 'no_submit_button',
    '#prefix' => '<div id="taxonomy-manager-toolbar-buttons">',
  );
  $form['toolbar']['weight-down'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons',
    ),
    '#value' => t('Down'),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['delete_confirm'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons delete',
    ),
    '#value' => t('Delete'),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['add_show'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons add',
    ),
    '#value' => t('Add'),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['move_show'] = array(
    '#type' => 'button',
    '#value' => t('Move'),
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons move',
    ),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['merge_show'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons merge',
    ),
    '#value' => t('Merge'),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['export_show'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons export',
    ),
    '#value' => t('CSV Export'),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['wrapper'] = array(
    '#type' => 'markup',
    '#value' => '<div id="taxonomy-manager-toolbar-throbber"></div><div class="clear"></div>',
    '#weight' => 20,
    '#prefix' => '</div>',
  );
  $form['toolbar_forms_wrapper'] = array(
    '#type' => 'markup',
    '#value' => '<div id="taxonomy-manager-toolbar-forms"></div>',
  );
  $form += taxonomy_manager_add_form($voc);
  $form += taxonomy_manager_merge_form($voc);
  $form += taxonomy_manager_move_form($voc);
  $form += taxonomy_manager_confirm_delete($voc);
  $form += taxonomy_manager_export_form($voc);
  if ($tid) {
    $form += taxonomy_manager_form_term_data($tid);
  }
  else {
    $form['term_data'] = array(
      '#tree' => TRUE,
    );
  }

  // add save button for term_data already to the form array,
  // but do not render (see theme_taxonomy_manager_form) if not needed
  // otherwise an #ahah callback on dynamically added forms makes problems
  $form['term_data']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save changes'),
    '#submit' => array(
      '',
    ),
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons save',
    ),
    '#ahah' => array(
      'path' => 'admin/content/taxonomy_manager/termdata/edit',
      'method' => 'replace',
      'event' => 'click',
      'wrapper' => 'taxonomy-term-data',
    ),
    '#weight' => 20,
  );
  return $form;
}