function hs_taxonomy_form_taxonomy_form_vocabulary_alter in Hierarchical Select 6.3
File
- modules/
hs_taxonomy.module, line 13 - Implementation of the Hierarchical Select API for the Taxonomy module.
Code
function hs_taxonomy_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
module_load_include('inc', 'hierarchical_select', 'includes/common');
$vid = isset($form['vid']) ? $form['vid']['#value'] : NULL;
$vocabulary = $vid ? taxonomy_vocabulary_load($vid) : NULL;
// Don't add the per-vocabulary settings for Hierarchical Select when the
// vocabulary still needs to be created or is a freetagging vocabulary.
if (!$vid || $vocabulary->tags) {
return;
}
if (variable_get("taxonomy_hierarchical_select_{$vid}", 0)) {
$form['settings']['tags']['#attributes']['disabled'] = TRUE;
$form['settings']['tags']['#description'] = t("This setting is irrelevant when you're using Hierarchical Select.\n <br />Use Hierarchical Select's %editability-settings instead.", array(
'%editability-settings' => t('Editability settings'),
));
$form['settings']['multiple']['#attributes']['disabled'] = TRUE;
$form['settings']['multiple']['#description'] = t("This setting is managed by the Hierarchical Select configuration, by\n the %enable-dropbox setting.", array(
'%enable-dropbox' => t('Enable the dropbox'),
));
}
$split = array_search('weight', array_keys($form)) + 1;
$first_part = array_slice($form, 0, $split);
$second_part = array_slice($form, $split);
$form = $first_part;
$form['hierarchical_select_status'] = array(
'#type' => 'checkbox',
'#title' => '<strong>' . t('Use the Hierarchical Select form element for this vocabulary.') . '</strong>',
'#default_value' => variable_get("taxonomy_hierarchical_select_{$vid}", 0),
'#description' => t('When checked, the %free_tagging and %multiple_values settings will
be managed by the Hierarchical Select configuration.', array(
'%free_tagging' => t('Free tagging'),
'%multiple_values' => t('Multiple values'),
)),
);
// Add the Hierarchical Select config form.
$module = 'hs_taxonomy';
$params = array(
'vid' => $vid,
'exclude_tid' => NULL,
'root_term' => NULL,
'entity_count_for_node_type' => NULL,
);
$config_id = "taxonomy-{$vid}";
$defaults = array(
// Enable the save_lineage setting by default if the multiple parents
// vocabulary option is enabled.
'save_lineage' => (int) ($vocabulary->hierarchy == 2),
'editability' => array(
'max_levels' => _hs_taxonomy_hierarchical_select_get_depth($vid),
),
);
$strings = array(
'hierarchy' => t('vocabulary'),
'hierarchies' => t('vocabularies'),
'item' => t('term'),
'items' => t('terms'),
'item_type' => t('term type'),
'entity' => t('node'),
'entities' => t('nodes'),
);
$max_hierarchy_depth = _hs_taxonomy_hierarchical_select_get_depth($vid);
$preview_is_required = $vocabulary->required;
$form['hierarchical_select'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
// The forum selection requires that only the deepest term is saved!
// See http://drupal.org/node/241766#comment-808464.
if ($vid == variable_get('forum_nav_vocabulary', -1)) {
$form['hierarchical_select']['save_lineage']['#value'] = 0;
$form['hierarchical_select']['save_lineage']['#attributes'] = array(
'disabled' => 'disabled',
);
$form['hierarchical_select']['save_lineage']['#description'] .= '<br />' . t('This is the vocabulary that will be used for forum navigation and it
<strong>always</strong> requires the %dont_save_lineage setting to be
set!', array(
'%dont_save_lineage' => t('Save only the deepest term'),
));
}
// Add the the submit handler for the Hierarchical Select config form.
$parents = array(
'hierarchical_select',
);
$form['#submit'][] = 'hierarchical_select_common_config_form_submit';
$form['#hs_common_config_form_parents'] = $parents;
// Add a validate callback to override the freetagging and multiple select
// settings if necessary.
$form['#validate'][] = 'hierarchical_select_taxonomy_form_vocabulary_validate';
$form['#submit'][] = 'hierarchical_select_taxonomy_form_vocabulary_submit';
// The original #submit callback(s) has/have to be executed afterwards.
$form['#submit'] = array_merge($form['#submit'], $second_part['#submit']);
$form += $second_part;
}