active_tags.module in Active Tags 5
Same filename and directory in other branches
Active Tags widget for free tagging taxonomies
File
active_tags.moduleView source
<?php
/**
* @file
* Active Tags widget for free tagging taxonomies
*/
function active_tags_init() {
if (arg(2) == 'edit' || arg(1) == 'add') {
drupal_add_css(drupal_get_path('module', 'active_tags') . '/active_tags.css', 'module');
$settings = array();
foreach (taxonomy_get_vocabularies() as $id => $values) {
if (variable_get('active_tags_' . $id, 0) == 1) {
$settings[] = "#edit-taxonomy-tags-{$id}";
}
}
drupal_add_js(array(
'active_tags' => $settings,
), 'setting');
drupal_add_js(drupal_get_path('module', 'active_tags') . '/active_tags.js', 'module');
}
}
function active_tags_form_alter($form_id, &$form) {
if ($form_id == 'taxonomy_form_vocabulary') {
$form['active_tags'] = array(
'#type' => 'checkbox',
'#title' => t('Active Tags'),
'#weight' => 10,
'#default_value' => isset($form['vid']['#value']) ? variable_get('active_tags_' . $form['vid']['#value'], 0) : 0,
'#description' => t('Swaps this vocabulary widget for an enhanced tag field if browser supports javascript.'),
);
$form['submit']['#weight'] = 11;
if (isset($form['delete'])) {
$form['delete']['#weight'] = 12;
}
$form['#validate'] = array(
'active_tags_form_vocabulary_validate' => array(),
);
$form['#submit'] += array(
'active_tags_form_vocabulary_submit' => array(),
);
}
}
function active_tags_form_vocabulary_validate($form_id, &$form_values) {
if ($form_values['active_tags'] == 1 && $form_values['tags'] != 1) {
form_set_error('active_tags', t('Active Tags can only be used with Free Tag Vocabularies'));
}
}
function active_tags_form_vocabulary_submit($form_id, &$form_values) {
variable_set('active_tags_' . $form_values['vid'], $form_values['active_tags']);
}
Functions
Name | Description |
---|---|
active_tags_form_alter | |
active_tags_form_vocabulary_submit | |
active_tags_form_vocabulary_validate | |
active_tags_init | @file Active Tags widget for free tagging taxonomies |