diff options
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r-- | modules/taxonomy/taxonomy.module | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index eb4ddf67f..6bf1bdc18 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -107,31 +107,31 @@ function taxonomy_menu($may_cache) { } function taxonomy_form_vocabulary($edit = array()) { - $form['name'] = array(type => 'textfield', title => t('Vocabulary name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The name for this vocabulary. Example: "Topic".'), required => TRUE); - - $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => t('Description of the vocabulary; can be used by modules.')); - $form['help'] = array(type => 'textfield', title => t('Help text'), default_value => $edit['help'], size => 60, maxlength => 255, description => t('Instructions to present to the user when choosing a term.')); - $form['nodes'] = array(type => 'checkboxes', title => t('Types'), default_value => $edit['nodes'], options => node_get_types(), description => t('A list of node types you want to associate with this vocabulary.'), required => TRUE); - $form['hierarchy'] = array(type => 'radios', title => t('Hierarchy'), default_value => $edit['hierarchy'], options => array(t('Disabled'), t('Single'), t('Multiple')), description => t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy')))); - $form['relations'] = array(type => 'checkbox', title => t('Related terms'), default_value => $edit['relations'], return_value => 1, description => t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms')))); - $form['tags'] = array(type => 'checkbox', title => t('Free tagging'), default_value => $edit['tags'], return_value => 1, description => t('Content is categorized by typing terms instead of choosing from a list.')); - $form['multiple'] = array(type => 'checkbox', title => t('Multiple select'), default_value => $edit['multiple'], return_value => 1, description => t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).')); - $form['required'] = array(type => 'checkbox', title => t('Required'), default_value => $edit['required'], return_value => 1, description => t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.')); - $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.')); + $form['name'] = array('#type' => 'textfield', '#title' => t('Vocabulary name'), '#default_value' => $edit['name'], '#size' => 60, '#maxlength' => 64, '#description' => t('The name for this vocabulary. Example: "Topic".'), '#required' => TRUE); + + $form['description'] = array('#type' => 'textarea', '#title' => t('Description'), '#default_value' => $edit['description'], '#cols' => 60, '#rows' => 5, '#description' => t('Description of the vocabulary; can be used by modules.')); + $form['help'] = array('#type' => 'textfield', '#title' => t('Help text'), '#default_value' => $edit['help'], '#size' => 60, '#maxlength' => 255, '#description' => t('Instructions to present to the user when choosing a term.')); + $form['nodes'] = array('#type' => 'checkboxes', '#title' => t('Types'), '#default_value' => $edit['nodes'], '#options' => node_get_types(), '#description' => t('A list of node types you want to associate with this vocabulary.'), '#required' => TRUE); + $form['hierarchy'] = array('#type' => 'radios', '#title' => t('Hierarchy'), '#default_value' => $edit['hierarchy'], '#options' => array(t('Disabled'), t('Single'), t('Multiple')), '#description' => t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy')))); + $form['relations'] = array('#type' => 'checkbox', '#title' => t('Related terms'), '#default_value' => $edit['relations'], '#return_value' => 1, '#description' => t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms')))); + $form['tags'] = array('#type' => 'checkbox', '#title' => t('Free tagging'), '#default_value' => $edit['tags'], '#return_value' => 1, '#description' => t('Content is categorized by typing terms instead of choosing from a list.')); + $form['multiple'] = array('#type' => 'checkbox', '#title' => t('Multiple select'), '#default_value' => $edit['multiple'], '#return_value' => 1, '#description' => t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).')); + $form['required'] = array('#type' => 'checkbox', '#title' => t('Required'), '#default_value' => $edit['required'], '#return_value' => 1, '#description' => t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.')); + $form['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $edit['weight'], '#delta' => 10, '#description' => t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.')); // Add extra vocabulary form elements. $extra = module_invoke_all('taxonomy', 'form', 'vocabulary'); if (is_array($extra)) { foreach ($extra as $key => $element) { - $extra[$key][weight] = isset($extra[$key][weight]) ? $nodeapi[$key][weight] : -18; + $extra[$key]['#weight'] = isset($extra[$key]['#weight']) ? $nodeapi[$key]['#weight'] : -18; } $form = array_merge($form, $extra); } - $form['submit'] = array(type => 'submit', value => t('Submit')); + $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); if ($edit['vid']) { - $form['delete'] = array(type => 'submit', value => t('Delete')); - $form['vid'] = array(type => 'hidden', value => $edit['vid']); + $form['delete'] = array('#type' => 'submit', '#value' => t('Delete')); + $form['vid'] = array('#type' => 'hidden', '#value' => $edit['vid']); } return drupal_get_form('taxonomy_form_vocabulary', $form); } @@ -189,9 +189,9 @@ function taxonomy_del_vocabulary($vid) { function _taxonomy_confirm_del_vocabulary($vid) { $vocabulary = taxonomy_get_vocabulary($vid); - $form['type'] = array(type => 'hidden', value => 'vocabulary'); - $form['vid'] = array(type => 'hidden', value => $vid); - $form['name'] = array(type => 'hidden', value => $vocabulary->name); + $form['type'] = array('#type' => 'hidden', '#value' => 'vocabulary'); + $form['vid'] = array('#type' => 'hidden', '#value' => $vid); + $form['name'] = array('#type' => 'hidden', '#value' => $vocabulary->name); return confirm_form('vocabulary_confirm_delete', $form, t('Are you sure you want to delete the vocabulary %title?', array('%title' => theme('placeholder', $vocabulary->name))), @@ -204,9 +204,9 @@ function taxonomy_form_term($edit = array()) { $vocabulary_id = isset($edit['vid']) ? $edit['vid'] : arg(4); $vocabulary = taxonomy_get_vocabulary($vocabulary_id); - $form['name'] = array(type => 'textfield', title => t('Term name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The name for this term. Example: "Linux".'), required => TRUE); + $form['name'] = array('#type' => 'textfield', '#title' => t('Term name'), '#default_value' => $edit['name'], '#size' => 60, '#maxlength' => 64, '#description' => t('The name for this term. Example: "Linux".'), '#required' => TRUE); - $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => t('A description of the term.')); + $form['description'] = array('#type' => 'textarea', '#title' => t('Description'), '#default_value' => $edit['description'], '#cols' => 60, '#rows' => 5, '#description' => t('A description of the term.')); if ($vocabulary->hierarchy) { $parent = array_keys(taxonomy_get_parents($edit['tid'])); @@ -230,28 +230,28 @@ function taxonomy_form_term($edit = array()) { $form['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid'])); } - $form['synonyms'] = array(type => 'textarea', title => t('Synonyms'), default_value => implode("\n", taxonomy_get_synonyms($edit['tid'])), cols => 60, rows => 5, description => t('<a href="%help-url">Synonyms</a> of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms')))); - $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.')); + $form['synonyms'] = array('#type' => 'textarea', '#title' => t('Synonyms'), '#default_value' => implode("\n", taxonomy_get_synonyms($edit['tid'])), '#cols' => 60, '#rows' => 5, '#description' => t('<a href="%help-url">Synonyms</a> of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms')))); + $form['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $edit['weight'], '#delta' => 10, '#description' => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.')); // Add extra term form elements. $extra = module_invoke_all('taxonomy', 'term', 'vocabulary'); if (is_array($extra)) { foreach ($extra as $key => $element) { - $extra[$key][weight] = isset($extra[$key][weight]) ? $nodeapi[$key][weight] : -18; + $extra[$key]['#weight'] = isset($extra[$key]['#weight']) ? $nodeapi[$key]['#weight'] : -18; } $form = array_merge($form, $extra); } - $form['vid'] = array(type => 'hidden', value => $vocabulary->vid); - $form['submit'] = array(type => 'submit', value => t('Submit')); + $form['vid'] = array('#type' => 'hidden', '#value' => $vocabulary->vid); + $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); if ($edit['tid']) { - $form['delete'] = array(type => 'submit', value => t('Delete')); - $form['tid'] = array(type => 'hidden', value => $edit['tid']); + $form['delete'] = array('#type' => 'submit', '#value' => t('Delete')); + $form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']); } else { - $form['destination'] = array(type => 'hidden', value => $_GET['q']); + $form['destination'] = array('#type' => 'hidden', '#value' => $_GET['q']); } return drupal_get_form('taxonomy_form_term', $form); @@ -353,8 +353,8 @@ function taxonomy_del_term($tid) { function _taxonomy_confirm_del_term($tid) { $term = taxonomy_get_term($tid); - $form['type'] = array(type => 'hidden', value => 'term'); - $form['tid'] = array(type => 'hidden', value => $tid); + $form['type'] = array('#type' => 'hidden', '#value' => 'term'); + $form['tid'] = array('#type' => 'hidden', '#value' => $tid); return confirm_form('term_confirm_delete', $form, t('Are you sure you want to delete the term %title?', array('%title' => theme('placeholder', $term->name))), @@ -489,7 +489,7 @@ function taxonomy_get_vocabularies($type = NULL) { /** * Generate a form for selecting terms to associate with a node. */ -function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy') { +function taxonomy_node_form($node) { if (!array_key_exists('taxonomy', $node)) { if ($node->nid) { $terms = taxonomy_node_get_terms($node->nid); @@ -502,7 +502,7 @@ function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy') $terms = $node->taxonomy; } - $c = db_query(db_rewrite_sql("SELECT v.*, n.type FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $type); + $c = db_query(db_rewrite_sql("SELECT v.*, n.type FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $node->type); while ($vocabulary = db_fetch_object($c)) { if ($vocabulary->tags) { $typed_terms = array(); @@ -519,21 +519,21 @@ function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy') } $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL); - - $form[$name]['tags'][$vocabulary->vid] = array(type => textfield, default_value => $typed_string, size => 60, maxlength => 100, autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => $vocabulary->required, title => $vocabulary->name, description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").')); + $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => textfield, '#default_value' => $typed_string, '#size' => 60, '#maxlength' => 100, '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid, '#required' => $vocabulary->required, '#title' => $vocabulary->name, '#description' => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").')); } else { $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms); - $form[$name][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name); - if ($vocabulary->multiple) { - $form[$name][$vocabulary->vid][parents] = array($name); - } - else { - $form[$name][$vocabulary->vid][tree] = TRUE; - } + $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, 'taxonomy'); } } - return $form ? $form : array(); + if ($form) { + $form['taxonomy']['#tree'] = TRUE; + $form['taxonomy']['#weight'] = -15; + return $form; + } + else { + return array(); + } } /** @@ -904,7 +904,7 @@ function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $descripti $value = $tree[0]->tid; } } - return array(type => 'select', title => $title, default_value => $value, options => $options, description => $description, multiple => $multiple, size => $multiple ? 'size="'. min(12, count($options)) .'"' : 0, weight => -15); + return array('#type' => 'select', '#title' => $title, '#default_value' => $value, '#options' => $options, '#description' => $description, '#multiple' => $multiple, '#size' => $multiple ? 'size="'. min(12, count($options)) .'"' : 0, '#weight' => -15); } function _taxonomy_depth($depth, $graphic = '--') { @@ -1037,6 +1037,9 @@ function taxonomy_nodeapi($node, $op, $arg = 0) { case 'rss item': return taxonomy_rss_item($node); break; + case 'form': + return taxonomy_node_form($node); + break; } } |