summaryrefslogtreecommitdiff
path: root/modules/taxonomy/taxonomy.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-12-05 09:11:33 +0000
committerDries Buytaert <dries@buytaert.net>2005-12-05 09:11:33 +0000
commit28fdb3975e2bc53061277f4fdb1147dc8d3ba128 (patch)
tree06c355049d6e98b30417addd2a0942962e4f18cc /modules/taxonomy/taxonomy.module
parent3e36be3b24423566e6d9de2c1c8cbea5ca68b295 (diff)
downloadbrdo-28fdb3975e2bc53061277f4fdb1147dc8d3ba128.tar.gz
brdo-28fdb3975e2bc53061277f4fdb1147dc8d3ba128.tar.bz2
- Patch #39778 by chx: obliterate nodeapi op form in favor of the forms API's way of doing things. Tested with help from webchick.
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r--modules/taxonomy/taxonomy.module72
1 files changed, 35 insertions, 37 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index f58f6db29..52fec1033 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -500,51 +500,52 @@ function taxonomy_get_vocabularies($type = NULL) {
/**
* Generate a form for selecting terms to associate with a node.
*/
-function taxonomy_node_form($node) {
- if (!array_key_exists('taxonomy', $node)) {
- if ($node->nid) {
- $terms = taxonomy_node_get_terms($node->nid);
+function taxonomy_form_alter($form_id, &$form) {
+ if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
+ $node = $form['#node'];
+
+ if (!array_key_exists('taxonomy', $node)) {
+ if ($node->nid) {
+ $terms = taxonomy_node_get_terms($node->nid);
+ }
+ else {
+ $terms = array();
+ }
}
else {
- $terms = array();
+ $terms = $node->taxonomy;
}
- }
- else {
- $terms = $node->taxonomy;
- }
- $c = db_query(db_rewrite_sql("SELECT v.* 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();
- foreach ($terms as $term) {
- if ($term->vid == $vocabulary->vid) {
+ $c = db_query(db_rewrite_sql("SELECT v.* 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);
- // Commas and quotes in terms are special cases, so encode 'em.
- if (preg_match('/,/', $term->name) || preg_match('/"/', $term->name)) {
- $term->name = '"'.preg_replace('/"/', '""', $term->name).'"';
- }
+ while ($vocabulary = db_fetch_object($c)) {
+ if ($vocabulary->tags) {
+ $typed_terms = array();
+ foreach ($terms as $term) {
+ if ($term->vid == $vocabulary->vid) {
- $typed_terms[] = $term->name;
+ // Commas and quotes in terms are special cases, so encode 'em.
+ if (preg_match('/,/', $term->name) || preg_match('/"/', $term->name)) {
+ $term->name = '"'.preg_replace('/"/', '""', $term->name).'"';
+ }
+
+ $typed_terms[] = $term->name;
+ }
}
- }
- $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
+ $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
- $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield', '#default_value' => $typed_string, '#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, '#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['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, 'taxonomy');
+ }
}
- else {
- $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms);
- $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, 'taxonomy');
+ if (isset($form['taxonomy'])) {
+ $form['taxonomy']['#tree'] = TRUE;
+ $form['taxonomy']['#weight'] = -15;
}
}
- if ($form) {
- $form['taxonomy']['#tree'] = TRUE;
- $form['taxonomy']['#weight'] = -15;
- return $form;
- }
- else {
- return array();
- }
}
/**
@@ -1056,9 +1057,6 @@ function taxonomy_nodeapi($node, $op, $arg = 0) {
case 'rss item':
return taxonomy_rss_item($node);
break;
- case 'form':
- return taxonomy_node_form($node);
- break;
}
}