function community_tags_settings in Community Tags 6
Same name and namespace in other branches
- 5 community_tags.module \community_tags_settings()
- 6.2 community_tags.admin.inc \community_tags_settings()
- 7 community_tags.admin.inc \community_tags_settings()
Form builder; Builds the settings form.
1 string reference to 'community_tags_settings'
- community_tags_menu in ./
community_tags.module - Implementation of hook_menu().
File
- ./
community_tags.admin.inc, line 15 - community_tags.admin.inc
Code
function community_tags_settings() {
$form = array();
// community_tags_rehash();
if ($broken = _community_tags_get_count_of_broken_tags()) {
drupal_set_message(t('There are @count broken community tags that reference missing terms, nodes, or users. Click <a href="@url">here</a> to delete them.', array(
'@count' => $broken,
'@url' => url('admin/settings/community-tags/ops/broken'),
)), 'warning');
}
// Build list of available free-tagging vocabularies
$vocabularies = _community_tags_get_settings();
// stat query for all ctags even for invalid combos - e.g. unassigned content type
$counts = _community_tags_get_tag_counts_by_type_and_vocabulary();
// put tag counts into vocabularies array. If a new type is found for a vocabulary
// then tags are left over from a previous configuration - i.e. content type was assigned for tagging but now is not.
foreach ($counts as $vid => $counts_by_type) {
foreach ($counts_by_type as $type => $count) {
if (!isset($vocabularies[$vid]['types'][$type])) {
$content_type = node_get_types('type', $type);
$vocabularies[$vid]['types'][$type] = array(
'type_name' => $content_type->name,
'tag_count' => $count->tag_count,
'assigned' => FALSE,
);
}
else {
$vocabularies[$vid]['types'][$type]['tag_count'] = $count->tag_count;
}
}
}
$missing_tag_counts = _community_tags_get_all_out_of_sync_missing_tag_counts();
$missing_termnode_counts = _community_tags_get_all_out_of_sync_missing_node_terms_counts();
foreach ($vocabularies as $vid => $vocabulary) {
foreach ($vocabulary['types'] as $type => $type_settings) {
$vocabularies[$vid]['types'][$type]['missing_tag_count'] = !empty($missing_tag_counts[$vid][$type]) ? $missing_tag_counts[$vid][$type] : 0;
$vocabularies[$vid]['types'][$type]['missing_termnode_count'] = !empty($missing_termnode_counts[$vid][$type]) ? $missing_termnode_counts[$vid][$type] : 0;
}
}
$form['#theme'] = 'community_tags_settings';
$form['community_tags_settings'] = array(
'#title' => t('Community tags vocabulary settings'),
'#tree' => TRUE,
'#type' => 'fieldset',
);
$display_handler_options = _community_tags_get_display_handler_options();
foreach ($vocabularies as $vid => $vocabulary) {
$enabled_content_types_for_vocabulary = count($content_types);
$form['community_tags_settings'][$vid] = array(
'#title' => l($vocabulary['name'], 'admin/content/taxonomy/edit/vocabulary/' . $vid, array(
'query' => drupal_get_destination(),
)),
'#type' => 'fieldset',
'#tree' => TRUE,
);
$form['community_tags_settings'][$vid]['tagging'] = array(
'#title' => t('Free-tagging'),
'#type' => 'item',
'#value' => $vocabulary['tagging'] ? t('yes') : t('no'),
);
$form['community_tags_settings'][$vid]['is_enabled'] = array(
'#title' => t('Enable community tagging'),
'#type' => 'checkbox',
'#default_value' => $vocabulary['CT_enabled'],
);
$form['community_tags_settings'][$vid]['types'] = array(
'#title' => t('Content type settings'),
// '#tree' => count($vocabulary['types']) > 0 ? TRUE : FALSE,
'#tree' => TRUE,
'#type' => 'item',
);
foreach ($vocabulary['types'] as $type_id => $type) {
$is_valid_CT_vocabulary_and_type = $type['assigned'] && $vocabulary['tagging'] && $vocabulary['CT_enabled'];
$type_title = l($type['type_name'], 'admin/content/node-type/' . $type_id, array(
'query' => drupal_get_destination(),
));
$type_description = t('Content types marked with an asterisk (*) indicate that the type is not enabled for the vocabulary but community tags exist from a previous configuration.');
if (!$type['assigned']) {
$type_title .= '*';
}
$form['community_tags_settings'][$vid]['types'][$type_id] = array(
'#title' => $type_title,
'#type' => 'fieldset',
'#tree' => TRUE,
'#description' => $type_description,
);
$form['community_tags_settings'][$vid]['types'][$type_id]['is_valid'] = array(
'#type' => 'hidden',
'#value' => $is_valid_CT_vocabulary_and_type,
);
// $form['community_tags_settings'][$vid]['types'][$type_id]['assigned'] = array(
// '#title' => t('Assigned'),
// '#type' => 'checkbox',
// '#disabled' => TRUE,
// '#default_value' => $type['assigned'],
// );
$form['community_tags_settings'][$vid]['types'][$type_id]['display_handler'] = array(
'#title' => t('Display'),
'#type' => $is_valid_CT_vocabulary_and_type ? 'select' : 'hidden',
'#default_value' => isset($display_handler_options[$type['display_handler']]) ? $type['display_handler'] : 'links',
'#options' => $display_handler_options,
);
$form['community_tags_settings'][$vid]['types'][$type_id]['synchronised'] = array(
'#title' => t('Sync Nodes'),
'#type' => $is_valid_CT_vocabulary_and_type ? 'checkbox' : 'hidden',
'#default_value' => $type['opmode'] & COMMUNITY_TAGS_OPMODE_SYNC,
'#description' => t('Sync Nodes: When a community tag is removed, the term will be removed from the node if this option is set.'),
);
$form['community_tags_settings'][$vid]['types'][$type_id]['redundant_terms'] = array(
'#title' => t('Sync Terms'),
'#type' => $is_valid_CT_vocabulary_and_type ? 'checkbox' : 'hidden',
'#default_value' => $type['opmode'] & COMMUNITY_TAGS_OPMODE_DELETE_ORPHAN_TERMS,
'#description' => t('Sync Terms: When a community tag is removed and the term referenced by it is no longer used, then the term is deleted if this option is set.'),
);
$form['community_tags_settings'][$vid]['types'][$type_id]['tag_count'] = array(
'#title' => t('Tag count'),
'#type' => 'item',
'#value' => isset($type['tag_count']) ? $type['tag_count'] : 0,
);
$operations = array();
if ($is_valid_CT_vocabulary_and_type) {
// operations for valid enabled CT vocabulary content type combinations
// add in deleted orphaned terms - need to encapsulate all this
if ($type['missing_tag_count']->missing_ctag_count > 0 || $type['opmode'] & COMMUNITY_TAGS_OPMODE_SYNC && $type['missing_termnode_count']->missing_termnode_count > 0 || FALSE) {
$operations[] = array(
'title' => t('rebuild'),
'href' => "admin/settings/community-tags/ops/rebuild/{$vid}/{$type_id}",
'query' => drupal_get_destination(),
);
}
}
if (isset($type['tag_count']) && $type['tag_count'] > 0) {
// operations for any CT vocabulary that has tags
$operations[] = array(
'title' => t('purge'),
'href' => "admin/settings/community-tags/ops/purge/{$vid}/{$type_id}",
'query' => drupal_get_destination(),
);
}
$form['community_tags_settings'][$vid]['types'][$type_id]['ops'] = array(
'#title' => t('Operations'),
'#value' => !empty($operations) ? theme('links', $operations, array(
'class' => 'links inline',
)) : '',
'#type' => 'item',
);
}
}
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}