summaryrefslogtreecommitdiff
path: root/modules/taxonomy.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-10-07 06:11:12 +0000
committerDries Buytaert <dries@buytaert.net>2005-10-07 06:11:12 +0000
commit7e1527ee61bc10b3765b95b9af8faaa2254da5a8 (patch)
tree2225c7f571b4a3f635564f8281406a12b2a271a7 /modules/taxonomy.module
parent7b5b460534e5c54b07d28467c2aa2fc670c714e4 (diff)
downloadbrdo-7e1527ee61bc10b3765b95b9af8faaa2254da5a8.tar.gz
brdo-7e1527ee61bc10b3765b95b9af8faaa2254da5a8.tar.bz2
- Patch #29465: new form API by Adrian et al.
TODO: + The contact.module was broken; a new patch for contact.module is needed. + Documentation is needed. + The most important modules need to be updated ASAP.
Diffstat (limited to 'modules/taxonomy.module')
-rw-r--r--modules/taxonomy.module138
1 files changed, 73 insertions, 65 deletions
diff --git a/modules/taxonomy.module b/modules/taxonomy.module
index 9f93a684b..5574520a1 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -107,28 +107,33 @@ function taxonomy_menu($may_cache) {
}
function taxonomy_form_vocabulary($edit = array()) {
- $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 60, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE);
- // Prepend extra vocabulary form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'vocabulary', $edit));
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.'));
- $form .= form_textfield(t('Help text'), 'help', $edit['help'], 60, 255, t('Instructions to present to the user when choosing a term.'));
- $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], node_get_types(), t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE);
- $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), 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 .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms'))));
- $form .= form_checkbox(t('Free tagging'), 'tags', 1, $edit['tags'], t('Content is categorized by typing terms instead of choosing from a list.'));
- $form .= form_checkbox(t('Multiple select'), 'multiple', 1, $edit['multiple'], t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).'));
- $form .= form_checkbox(t('Required'), 'required', 1, $edit['required'], t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.'));
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.'));
- // Append extra vocabulary form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form post', 'vocabulary', $edit));
- $form .= form_submit(t('Submit'));
+ $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;
+ }
+ $form = array_merge($form, $extra);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['vid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('vid', $edit['vid']);
+ $form['delete'] = array(type => 'submit', value => t('Delete'));
+ $form['vid'] = array(type => 'hidden', value => $edit['vid']);
}
-
- return form($form);
+ return drupal_get_form('taxonomy_form_vocabulary', $form);
}
function taxonomy_save_vocabulary(&$edit) {
@@ -140,7 +145,7 @@ function taxonomy_save_vocabulary(&$edit) {
if ($edit['vid'] && $edit['name']) {
db_query('UPDATE {vocabulary} SET '. _taxonomy_prepare_update($data) .' WHERE vid = %d', $edit['vid']);
db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']);
- foreach ($edit['nodes'] as $type) {
+ foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);
@@ -152,7 +157,7 @@ function taxonomy_save_vocabulary(&$edit) {
else {
$data['vid'] = $edit['vid'] = db_next_id('{vocabulary}_vid');
db_query('INSERT INTO {vocabulary} '. _taxonomy_prepare_insert($data, 1) .' VALUES '. _taxonomy_prepare_insert($data, 2));
- foreach ($edit['nodes'] as $type) {
+ foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit);
@@ -184,28 +189,24 @@ function taxonomy_del_vocabulary($vid) {
function _taxonomy_confirm_del_vocabulary($vid) {
$vocabulary = taxonomy_get_vocabulary($vid);
- $extra = form_hidden('type', 'vocabulary');
- $extra .= form_hidden('vid', $vid);
- $extra .= form_hidden('name', $vocabulary->name);
-
- $output = theme('confirm',
- t('Are you sure you want to delete the vocabulary %title?', array('%title' => theme('placeholder', $vocabulary->name))),
- 'admin/taxonomy',
- t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
+ $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))),
+ 'admin/taxonomy', t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ t('Cancel'));
}
function taxonomy_form_term($edit = array()) {
$vocabulary_id = isset($edit['vid']) ? $edit['vid'] : arg(4);
$vocabulary = taxonomy_get_vocabulary($vocabulary_id);
- $form = form_textfield(t('Term name'), 'name', $edit['name'], 60, 64, t('The name for this term. Example: "Linux".'), NULL, TRUE);
- // Prepend extra term form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'term', $edit));
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('A description of the term.'));
+ $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.'));
if ($vocabulary->hierarchy) {
$parent = array_keys(taxonomy_get_parents($edit['tid']));
@@ -218,33 +219,42 @@ function taxonomy_form_term($edit = array()) {
$exclude[] = $edit['tid'];
if ($vocabulary->hierarchy == 1) {
- $form .= _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude);
+ $form['parent'] = _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude);
}
elseif ($vocabulary->hierarchy == 2) {
- $form .= _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude);
+ $form['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude);
}
}
if ($vocabulary->relations) {
- $form .= _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
+ $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 .= form_textarea(t('Synonyms'), 'synonyms', implode("\n", taxonomy_get_synonyms($edit['tid'])), 60, 5, 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 .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
- // Append extra term form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form post', 'term', $edit));
- $form .= form_hidden('vid', $vocabulary->vid);
- $form .= form_submit(t('Submit'));
+ $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;
+ }
+ $form = array_merge($form, $extra);
+ }
+
+
+ $form['vid'] = array(type => 'hidden', value => $vocabulary->vid);
+ $form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['tid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('tid', $edit['tid']);
+ $form['delete'] = array(type => 'submit', value => t('Delete'));
+ $form['tid'] = array(type => 'hidden', value => $edit['tid']);
}
else {
- $form .= form_hidden('destination', $_GET['q']);
+ $form['destination'] = array(type => 'hidden', value => $_GET['q']);
}
- return form($form);
+ return drupal_get_form('taxonomy_form_term', $form);
}
function taxonomy_save_term(&$edit) {
@@ -343,18 +353,15 @@ function taxonomy_del_term($tid) {
function _taxonomy_confirm_del_term($tid) {
$term = taxonomy_get_term($tid);
- $extra = form_hidden('type', 'term');
- $extra .= form_hidden('tid', $tid);
-
- $output = theme('confirm',
- t('Are you sure you want to delete the term %title?', array('%title' => theme('placeholder', $term->name))),
+ $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))),
'admin/taxonomy',
t('Deleting a term will delete all its children if there are any. This action cannot be undone.'),
t('Delete'),
- t('Cancel'),
- $extra);
-
- return $output;
+ t('Cancel'));
}
/**
@@ -511,14 +518,18 @@ 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);
- $result[] = form_autocomplete($vocabulary->name, "$name][tags][". $vocabulary->vid, $typed_string, 60, 100, 'taxonomy/autocomplete/'. $vocabulary->vid, t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'), NULL, ($vocabulary->required ? TRUE : FALSE));
+
+
+ $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 ? TRUE : FALSE), 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);
- $result[] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name);
+ $form[$name][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name);
}
}
- return $result ? $result : array();
+ return $form ? $form : array();
}
/**
@@ -889,8 +900,7 @@ function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $descripti
$value = $tree[0]->tid;
}
}
-
- return form_select($title, $name . ($multiple ? '' : ']['), $value, $options, $description, $multiple ? 'size="'. min(12, count($options)) .'"' : 0, $multiple);
+ 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 = '--') {
@@ -1288,5 +1298,3 @@ function taxonomy_autocomplete($vid, $string = '') {
exit();
}
}
-
-