You are here

function taxonomy_manager_form in Taxonomy Manager 7

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. 6 taxonomy_manager.admin.inc \taxonomy_manager_form()

defines forms for taxonomy manager interface

Parameters

$voc vocabulary:

$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
Implements hook_menu().
taxonomy_manager_tree_build_child_form in ./taxonomy_manager.module
callback for generating and rendering nested child forms (AHAH)
taxonomy_manager_tree_build_siblings_form in ./taxonomy_manager.module
callback for generating and rendering next siblings terms form (AHAH)

File

./taxonomy_manager.admin.inc, line 51

Code

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

  // Check for confirmation forms.
  if (isset($form_state['confirm_delete'])) {
    return taxonomy_manager_term_confirm_delete($form, $form_state, $voc->vid);
  }

  // By default use tid from term data form, except it is submitted from the load-tid helper and the tree needs to be refreshed.
  if (isset($form_state['values']['tid']) && !(isset($form_state['triggering_element']['#value']) && $form_state['triggering_element']['#value'] == "load term" && $form_state['values']['load-tid-refresh-tree'])) {
    $tid = $form_state['values']['tid'];
  }
  elseif (isset($form_state['triggering_element']['#value']) && $form_state['triggering_element']['#value'] == "load term" && $form_state['values']['load-tid-refresh-tree']) {
    $tid = $form_state['values']['load-tid'];
  }
  $module_path = drupal_get_path('module', 'taxonomy_manager') . '/';
  $form['#attached']['css'][] = $module_path . 'css/taxonomy_manager.css';
  $form['#attached']['js'][] = $module_path . 'js/hideForm.js';
  $form['#attached']['js'][] = $module_path . 'js/updateWeight.js';
  $form['#attached']['js'][] = $module_path . 'js/termData.js';
  $form['#attached']['js'][] = array(
    'data' => array(
      'termData' => array(
        'url' => url("admin/structure/taxonomy_manager/termdata/edit/" . $voc->vid),
      ),
    ),
    'type' => 'setting',
  );
  $form['#attached']['js'][] = array(
    'data' => array(
      'updateWeight' => array(
        'up' => 'edit-weight-up',
        'down' => 'edit-weight-down',
        'url' => url('admin/structure/taxonomy_manager/weight/'),
        'disable_mouseover' => variable_get('taxonomy_manager_disable_mouseover', 0),
      ),
    ),
    'type' => 'setting',
  );
  $form['#attached']['js'][] = array(
    'data' => array(
      'TMAjaxThrobber' => array(
        'add' => TRUE,
      ),
    ),
    'type' => 'setting',
  );
  $form['#attached']['js'][] = array(
    'data' => array(
      'taxonomy_manager' => array(
        'modulePath' => url($module_path) == $module_path ? $module_path : base_path() . $module_path,
      ),
    ),
    'type' => 'setting',
  );
  drupal_set_title(t("Taxonomy Manager - %voc_name", array(
    "%voc_name" => $voc->name,
  )), PASS_THROUGH);
  $form['voc'] = array(
    '#type' => 'value',
    "#value" => $voc,
  );

  // Helper forms for loading the term data form.
  // When a term link in the tree view gets clicked, the term id is written into the
  // load-tid textfield and aftwards the load-tid-submit button gets clicked, which
  // triggers the ajax system.
  $form['load-tid'] = array(
    '#type' => 'textfield',
    '#prefix' => '<div class="taxonomy-manager-term-load-helper">',
  );
  $form['load-tid-refresh-tree'] = array(
    '#type' => 'checkbox',
  );
  $form['load-tid-submit'] = array(
    '#type' => 'submit',
    '#value' => 'load term',
    '#submit' => array(
      'taxonomy_manager_load_tid_submit',
    ),
    '#ajax' => array(
      'callback' => 'taxonomy_manager_term_data_form_ajax_callback',
      'method' => 'replaceWith',
      'event' => 'click',
      'wrapper' => 'taxonomy-term-data-replace',
    ),
    '#suffix' => '</div>',
  );
  taxonomy_manager_form_voc_jumper($form, $form_state);
  if (_taxonomy_manager_voc_is_empty($voc->vid)) {
    $text = t('No terms available');
    $form['text'] = array(
      '#markup' => $text,
    );
    taxonomy_manager_add_form($form, $voc, FALSE);
    return $form;
  }
  $form_state['cache'] = TRUE;
  $form['taxonomy']['#tree'] = TRUE;
  $form['taxonomy']['manager'] = array(
    '#type' => 'fieldset',
    '#title' => check_plain($voc->name) . _taxonomy_manager_select_all_helpers_markup(),
    '#weight' => 10,
    '#tree' => TRUE,
  );
  $form['taxonomy']['manager']['top'] = array(
    '#markup' => '',
    '#prefix' => '<div class="taxonomy-manager-tree-top">',
    '#suffix' => '</div>',
  );
  if (module_exists('i18n_taxonomy')) {
    if (i18n_taxonomy_vocabulary_mode($voc->vid, I18N_MODE_TRANSLATE)) {
      if ($tid) {
        $language = _taxonomy_manager_term_get_lang($tid);
      }
      else {
        $language = language_default()->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' => array(
            'language-selector',
          ),
        ),
      );
    }
  }
  $form['taxonomy']['manager']['top']['size'] = array(
    '#markup' => '<div class="taxonomy-manager-tree-size">' . theme("image", array(
      'path' => $module_path . "images/grippie.png",
      'alt' => t("Resize tree"),
      'title' => t("Resize tree"),
      'attributes' => array(
        'class' => "div-grippie",
      ),
    )) . '</div>',
  );
  if (isset($form_state['values']['double_tree_values']['left_tree_expand_terms']) && count($form_state['values']['double_tree_values']['left_tree_expand_terms'])) {
    $tids_to_expand = $form_state['values']['double_tree_values']['left_tree_expand_terms'];
  }
  elseif (isset($form_state['values']['searched_terms']) && count($form_state['values']['searched_terms'])) {
    $tids_to_expand = $form_state['values']['searched_terms'];
  }
  else {
    $tids_to_expand = $tid;
  }
  $form['taxonomy']['manager']['tree'] = array(
    '#type' => 'taxonomy_manager_tree',
    '#vid' => $voc->vid,
    '#pager' => TRUE,
    '#search_string' => $tid ? NULL : $filter,
    '#language' => isset($language) ? $language : '',
    '#terms_to_expand' => $tids_to_expand,
    '#terms_to_highlight' => $tids_to_expand,
  );
  $form['toolbar'] = array(
    '#type' => 'fieldset',
    '#title' => t('Toolbar'),
  );
  $form['toolbar']['weight_up'] = array(
    //'#type' => 'button',
    '#attributes' => array(
      'class' => array(
        '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' => array(
        'taxonomy-manager-buttons',
      ),
    ),
    '#value' => t('Down'),
    '#theme' => 'no_submit_button',
  );
  $form['toolbar']['wrapper'] = array(
    '#type' => 'markup',
    '#markup' => '<div id="taxonomy-manager-toolbar-throbber"></div><div class="clear"></div>',
    '#weight' => 20,
    '#prefix' => '</div>',
  );
  taxonomy_manager_add_form($form, $voc);
  taxonomy_manager_confirm_delete($form, $voc);
  taxonomy_manager_term_merge_form($form, $voc);
  taxonomy_manager_move_form($form, $voc);
  taxonomy_manager_export_form($form, $form_state, $voc);
  taxonomy_manager_double_tree_settings_form($form, $voc);
  taxonomy_manager_search_form($form, $voc);

  // A term clicked in tree-view and submitted through load-tid helper,
  // generate term data form.
  // Moved this code snippet to the bottom here to prevent needless
  // expanding of the tree for this tid.
  if (isset($form_state['values']['load-tid'])) {
    $tid = $form_state['values']['load-tid'];
  }
  elseif (isset($form_state['term']) && is_object($form_state['term'])) {
    $tid = $form_state['term']->tid;
  }
  taxonomy_manager_term_data_form($form, $form_state, $tid, $voc->vid);
  return $form;
}