vid); $form['term_trunk'] = array( '#type' => 'fieldset', '#title' => t('Merge Into'), '#prefix' => '
', '#suffix' => '
', '#tree' => TRUE, '#element_validate' => array('term_merge_form_base_term_trunk_validate'), ); // Array of currently available widgets for choosing term trunk. $term_trunk_widget_options = array( 'autocomplete' => 'Autocomplete', ); if (variable_get('taxonomy_override_selector', FALSE) && module_exists('hs_taxonomy')) { $term_trunk_widget_options['hs_taxonomy'] = t('Hierarchical Select'); $term_trunk_widget = 'hs_taxonomy'; } else { $term_trunk_widget_options['select'] = t('Select'); $term_trunk_widget = 'select'; } // If the vocabulary is too big, by default we want the trunk term widget to // be autocomplete instead of select or hs_taxonomy. if (count($tree) > 200) { $term_trunk_widget = 'autocomplete'; } // Override the term trunk widget if settings are found in $form_state. if (isset($form_state['values']['term_trunk']['widget']) && in_array($form_state['values']['term_trunk']['widget'], array_keys($term_trunk_widget_options))) { $term_trunk_widget = $form_state['values']['term_trunk']['widget']; } // TODO: the trunk term widgets should be implemented as cTools plugins. $form['term_trunk']['widget'] = array( '#type' => 'radios', '#title' => t('Widget'), '#required' => TRUE, '#options' => $term_trunk_widget_options, '#default_value' => $term_trunk_widget, '#description' => t('Choose what widget you prefer for entering the term trunk.'), '#ajax' => array( 'callback' => 'term_merge_form_term_trunk', 'wrapper' => 'term-merge-form-term-trunk', 'method' => 'replace', 'effect' => 'fade', ), ); // @todo: // There is a known bug, if user has selected something in one widget, and // then changes the widget, $form_states['values'] will hold the value for // term trunk form element in the format that is used in one widget, while // this value will be passed to another widget. This triggers different // unpleasant effects like showing tid instead of term's name or vice-versa. // I think we should just empty $form_state['values'] for the term trunk // form element when widget changes. Better ideas are welcome! $function = 'term_merge_form_term_trunk_widget_' . $term_trunk_widget; $function($form, $form_state, $vocabulary, $term_branch_value); // Ensuring the Merge Into form element has the same title no matter what // widget has been used. $form['term_trunk']['tid']['#title'] = t('Merge into'); // Adding necessary options of merging. $form += term_merge_merge_options_elements($vocabulary); } /** * Menu callback. * * Allow user to specify which terms to be merged into which term and any * other settings needed for the term merge action. * * @param object $vocabulary * Fully loaded taxonomy vocabulary object * @param object $term * Fully loaded taxonomy term object that should be selected as the default * merge term in the form. If the $vocabulary is omitted, the vocabulary of * $term is considered * * @return array * Array of the form in Form API format * * TODO: accidentally this function happens to implement hook_form() which is * definitely not my intention. This function must be renamed to a safer name. */ function term_merge_form($form, $form_state, $vocabulary = NULL, $term = NULL) { if (is_null($vocabulary)) { $vocabulary = taxonomy_vocabulary_load($term->vid); } if (!isset($form_state['storage']['confirm'])) { // We are at the set up step. $tree = taxonomy_get_tree($vocabulary->vid); $term_branch_value = is_null($term) ? array() : array($term->tid); if (variable_get('taxonomy_override_selector', FALSE) && module_exists('hs_taxonomy')) { // We use Hierarchical Select module if it's available and configured to // be used for taxonomy selects. $form['term_branch'] = array( '#type' => 'hierarchical_select', // @todo: figure out why #required => TRUE doesn't work. // As a matter of fact, this issue seems to cover our case. // http://drupal.org/node/1275862. //'#required' => TRUE, '#config' => array( 'module' => 'hs_taxonomy', 'params' => array( 'vid' => $vocabulary->vid, 'exclude_tid' => NULL, 'root_term' => FALSE, ), 'enforce_deepest' => 0, 'entity_count' => 0, 'require_entity' => 0, 'save_lineage' => 0, 'level_labels' => array( 'status' => 0, ), 'dropbox' => array( 'status' => 1, 'limit' => 0, ), 'editability' => array( 'status' => 0, ), 'resizable' => TRUE, 'render_flat_select' => 0, ), ); } else { // Falling back on a simple