You are here

function taxonomy_manager_double_tree_form in Taxonomy Manager 7

Same name and namespace in other branches
  1. 6.2 taxonomy_manager.admin.inc \taxonomy_manager_double_tree_form()
1 string reference to 'taxonomy_manager_double_tree_form'
taxonomy_manager_menu in ./taxonomy_manager.module
Implements hook_menu().

File

./taxonomy_manager.admin.inc, line 229

Code

function taxonomy_manager_double_tree_form($form, &$form_state, $voc1, $voc2, $tid = 0, $filter = NULL) {

  // Check for confirmation forms.
  if (isset($form_state['confirm_delete'])) {
    return taxonomy_manager_term_confirm_delete($form, $form_state, $voc1->vid, $voc2->vid);
  }
  $module_path = drupal_get_path('module', 'taxonomy_manager') . '/';
  $form = taxonomy_manager_form($form, $form_state, $voc1, $tid, $filter);
  $form['disable'] = array(
    '#markup' => l(t('Disable Double Tree'), 'admin/structure/taxonomy_manager/voc/' . $voc1->machine_name),
    '#weight' => -100,
  );
  $form['voc2'] = array(
    '#type' => 'value',
    "#value" => $voc2,
  );
  $form['taxonomy2'] = array(
    '#tree' => TRUE,
  );
  $form['taxonomy2']['manager'] = array(
    '#type' => 'fieldset',
    '#title' => check_plain($voc2->name) . _taxonomy_manager_select_all_helpers_markup(),
    '#weight' => 10,
    '#tree' => TRUE,
  );
  $form['taxonomy2']['manager']['top'] = array(
    '#value' => '',
    '#prefix' => '<div class="taxonomy-manager-tree-top">',
    '#suffix' => '</div>',
  );
  if (module_exists('i18n_taxonomy')) {
    if (i18n_taxonomy_vocabulary_mode($voc2->vid, I18N_MODE_TRANSLATE)) {
      if ($tid) {
        $language = _taxonomy_manager_term_get_lang($tid);
      }
      else {
        $language = language_default()->language;
      }
      $form['taxonomy2']['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['taxonomy2']['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']['right_tree_expand_terms']) && count($form_state['values']['double_tree_values']['right_tree_expand_terms'])) {
    $tids_to_expand = $form_state['values']['double_tree_values']['right_tree_expand_terms'];
  }
  else {
    $tids_to_expand = $tid;
  }
  $form['taxonomy2']['manager']['tree'] = array(
    '#type' => 'taxonomy_manager_tree',
    '#vid' => $voc2->vid,
    '#pager' => TRUE,
    '#search_string' => $tid ? NULL : $filter,
    '#language' => isset($language) ? $language : '',
    '#terms_to_expand' => $tids_to_expand,
    //@todo check if term coming through ajax
    '#terms_to_highlight' => $tids_to_expand,
  );
  $form['double-tree']['operations'] = array(
    '#tree' => TRUE,
  );
  $form['double-tree']['operations']['move_right'] = array(
    '#type' => 'image_button',
    '#attributes' => array(
      'title' => t('Move right'),
    ),
    '#src' => $module_path . "images/go-next.png",
    '#submit' => array(
      'taxonomy_manager_double_tree_move_submit',
    ),
    '#validate' => array(
      'taxonomy_manager_double_tree_move_validate',
    ),
    '#ajax' => array(
      'callback' => 'taxonomy_manager_double_tree_ajax_callback',
      'method' => 'replaceWith',
      'event' => 'click',
      'wrapper' => 'taxonomy-manager',
      'progress' => array(
        'type' => '',
      ),
    ),
    '#weight' => 20,
    '#prefix' => '<div class="taxonomy-manager-double-tree-operations-buttons">',
    '#suffix' => '</div>',
  );
  $form['double-tree']['operations']['move_left'] = array(
    '#type' => 'image_button',
    '#attributes' => array(
      'title' => t('Move left'),
    ),
    '#src' => $module_path . "images/go-previous.png",
    '#submit' => array(
      'taxonomy_manager_double_tree_move_submit',
    ),
    '#validate' => array(
      'taxonomy_manager_double_tree_move_validate',
    ),
    '#ajax' => array(
      'callback' => 'taxonomy_manager_double_tree_ajax_callback',
      'method' => 'replaceWith',
      'event' => 'click',
      'wrapper' => 'taxonomy-manager',
      'progress' => array(
        'type' => '',
      ),
    ),
    '#weight' => 20,
    '#prefix' => '<div class="taxonomy-manager-double-tree-operations-buttons">',
    '#suffix' => '</div>',
  );

  //switch operations
  if ($voc1->vid != $voc2->vid) {
    $form['double-tree']['operations']['move_right']['#attributes']['title'] = t('Switch selected terms and its children to the right voc');
    $form['double-tree']['operations']['move_right']['#submit'] = array(
      'taxonomy_manager_double_tree_switch_submit',
    );
    $form['double-tree']['operations']['move_right']['#validate'] = array(
      'taxonomy_manager_double_tree_switch_validate',
    );
    $form['double-tree']['operations']['move_left']['#attributes']['title'] = t('Switch selected terms and its children to the left voc');
    $form['double-tree']['operations']['move_left']['#submit'] = array(
      'taxonomy_manager_double_tree_switch_submit',
    );
    $form['double-tree']['operations']['move_left']['#validate'] = array(
      'taxonomy_manager_double_tree_switch_validate',
    );

    // Copy buttons
    $form['double-tree']['operations']['copy_right'] = $form['double-tree']['operations']['move_right'];
    $form['double-tree']['operations']['copy_left'] = $form['double-tree']['operations']['move_left'];
    $form['double-tree']['operations']['copy_right']['#attributes']['title'] = t('Copy selected term names to the right voc.');
    $form['double-tree']['operations']['copy_right']['#src'] = $module_path . "images/copy-right.png";
    $form['double-tree']['operations']['copy_right']['#submit'] = array(
      'taxonomy_manager_double_tree_copy_submit',
    );
    $form['double-tree']['operations']['copy_right']['#validate'] = array(
      'taxonomy_manager_double_tree_copy_validate',
    );
    $form['double-tree']['operations']['copy_right']['#weight'] = 22;
    $form['double-tree']['operations']['copy_left']['#attributes']['title'] = t('Copy selected term names to the left voc.');
    $form['double-tree']['operations']['copy_left']['#src'] = $module_path . "images/copy-left.png";
    $form['double-tree']['operations']['copy_left']['#submit'] = array(
      'taxonomy_manager_double_tree_copy_submit',
    );
    $form['double-tree']['operations']['copy_left']['#validate'] = array(
      'taxonomy_manager_double_tree_copy_validate',
    );
    $form['double-tree']['operations']['copy_left']['#weight'] = 23;
  }
  elseif (module_exists('i18n_taxonomy') && i18n_taxonomy_vocabulary_mode($voc2->vid, I18N_MODE_TRANSLATE)) {
    $form['double-tree']['operations']['add_translation'] = $form['double-tree']['operations']['move_right'];
    $form['double-tree']['operations']['add_translation']['#attributes']['title'] = t('Add Translation.');
    $form['double-tree']['operations']['add_translation']['#src'] = $module_path . "images/connect.png";
    $form['double-tree']['operations']['add_translation']['#submit'] = array(
      'taxonomy_manager_double_tree_add_translation_submit',
    );
    $form['double-tree']['operations']['add_translation']['#validate'] = array(
      'taxonomy_manager_double_tree_add_translation_validate',
    );
  }
  return $form;
}