You are here

function taxonomy_manager_form in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_form()
  2. 6 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:

1 call to taxonomy_manager_form()
taxonomy_manager_double_tree_form in ./taxonomy_manager.admin.inc
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 39
Taxonomy Manager Admin

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(array(
    'termData' => array(
      'url' => url("admin/content/taxonomy_manager/termdata/edit/" . $vid),
      'tid' => $tid,
      'term_url' => url('admin/content/taxonomy_manager/termdata/' . $vid),
    ),
  ), 'setting');

  //TODO check if values necessary and correct
  drupal_add_js(array(
    'updateWeight' => array(
      'up' => 'edit-weight-up',
      'down' => 'edit-weight-down',
      'url' => url('admin/content/taxonomy_manager/weight/'),
      'disable_mouseover' => variable_get('taxonomy_manager_disable_mouseover', 0),
    ),
  ), 'setting');
  drupal_add_js(array(
    'TMAjaxThrobber' => array(
      'add' => TRUE,
    ),
  ), 'setting');
  drupal_add_js(array(
    'taxonomy_manager' => array(
      'modulePath' => url($module_path) == $module_path ? $module_path : base_path() . $module_path,
    ),
  ), '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! Check this <a href="!list">list</a> for available vocabularies or <a href="!create">create</a> a new one', array(
      '!list' => url('admin/content/taxonomy_manager'),
      '!create' => url('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']['top'] = array(
    '#value' => '',
    '#prefix' => '<div class="taxonomy-manager-tree-top">',
    '#suffix' => '</div>',
  );
  if (module_exists('i18ntaxonomy')) {
    if (i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_TRANSLATE) {
      if ($tid) {
        $language = _taxonomy_manager_term_get_lang($tid);
      }
      else {
        $lang = language_default();
        $language = $lang->language;
      }
      $form['taxonomy']['manager']['top']['language'] = array(
        '#type' => 'select',
        '#title' => t('Language'),
        '#default_value' => $language,
        '#options' => array(
          '' => t('All'),
          'no language' => t('no language'),
        ) + locale_language_list('name'),
        '#attributes' => array(
          'class' => 'language-selector',
        ),
      );
    }
  }
  $form['taxonomy']['manager']['top']['size'] = array(
    '#value' => '<div class="taxonomy-manager-tree-size">' . theme("image", $module_path . "images/grippie.png", t("Resize tree"), t("Resize tree"), array(
      'class' => "div-grippie",
    )) . '</div>',
  );
  $form['taxonomy']['manager']['tree'] = array(
    '#type' => 'taxonomy_manager_tree',
    '#vid' => $vid,
    '#pager' => TRUE,
    '#search_string' => $tid ? NULL : $filter,
    '#language' => isset($language) ? $language : '',
    '#term_to_expand' => $tid,
  );
  $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>',
  );
  $search_options = array(
    'synonyms' => t('Include synonyms'),
    'subtrees' => t('Search under selected terms'),
  );
  if (module_exists('i18ntaxonomy')) {
    if (i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_TRANSLATE) {
      $search_options['language'] = t('Search within selected language');
    }
  }
  $form['search']['options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Search options'),
    '#options' => $search_options,
  );
  $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']['double_tree_show'] = array(
    '#type' => 'button',
    '#attributes' => array(
      'class' => 'taxonomy-manager-buttons double-tree',
    ),
    '#value' => t('Double Tree'),
    '#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);
  $form += taxonomy_manager_double_tree_settings_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',
      'progress' => array(
        'type' => '',
      ),
    ),
    '#weight' => 20,
  );
  return $form;
}