You are here

function hs_taxonomy_form_taxonomy_form_term_alter in Hierarchical Select 7.3

Same name and namespace in other branches
  1. 6.3 modules/hs_taxonomy.module \hs_taxonomy_form_taxonomy_form_term_alter()

File

modules/hs_taxonomy.module, line 166
Implementation of the Hierarchical Select API for the Taxonomy module.

Code

function hs_taxonomy_form_taxonomy_form_term_alter(&$form, &$form_state) {

  // Don't alter the form when taxonomy_override_selector is not TRUE (or 1).
  if (!variable_get('taxonomy_override_selector', FALSE)) {
    return;
  }

  // Don't alter the form when it's in confirmation mode.
  if (isset($form_state['confirm_delete']) || isset($form_state['confirm_parents'])) {
    return;
  }

  // Build an appropriate config.
  $vocabulary = $form['#vocabulary'];
  $vid = $vocabulary->vid;
  module_load_include('inc', 'hierarchical_select', 'includes/common');
  $config = array(
    'module' => 'hs_taxonomy',
    'params' => array(
      'vid' => $vid,
      'exclude_tid' => isset($form['#term']['tid']) ? $form['#term']['tid'] : NULL,
      'root_term' => TRUE,
    ),
    'enforce_deepest' => 0,
    'save_lineage' => 0,
    'level_labels' => array(
      'status' => FALSE,
      'labels' => array(),
    ),
    'dropbox' => array(
      'status' => variable_get('hs_taxonomy_enable_dropbox_on_term_form', 0),
      'limit' => 0,
    ),
    'editability' => array(
      'status' => 0,
    ),
    'entity_count' => array(
      'enable' => 0,
      'require_entity' => 0,
      'settings' => array(
        'count_children' => 0,
        'entity_types' => array(),
      ),
    ),
    'render_flat_select' => 0,
  );

  // Use Hierarchical Select for selecting the parent term(s).
  $parent_tid = array_keys(taxonomy_get_parents($form['#term']['tid']));
  $parent = !empty($parent_tid) ? $parent_tid : array(
    0,
  );
  $form['relations']['parent'] = array(
    '#type' => 'hierarchical_select',
    '#title' => t('Parents'),
    '#required' => TRUE,
    '#default_value' => $parent,
    '#config' => $config,
  );
  $form['relations']['parent']['#config']['dropbox']['title'] = t('All parent terms');
}