summaryrefslogtreecommitdiff
path: root/modules/forum/forum.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/forum/forum.module')
-rw-r--r--modules/forum/forum.module80
1 files changed, 36 insertions, 44 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index fdc06eb17..5ee5fa3dc 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -233,6 +233,31 @@ function forum_form_alter($form_id, &$form) {
unset($form['nodes']['forum']);
}
}
+
+ if ($form_id == 'node_delete_confirm' && $form['node']['#value']->type == 'forum') {
+ $form['#submit']['forum_node_delete_confirm_submit'] = array();
+ }
+}
+
+/**
+ * Check in particular that only a "leaf" term in the associated taxonomy
+ * vocabulary is selected, not a "container" term.
+ */
+function forum_node_validate($form_id, $node) {
+ $node = (object)$node;
+ if ($node->taxonomy) {
+ // Extract the node's proper topic ID.
+ $vocabulary = variable_get('forum_nav_vocabulary', '');
+ $containers = variable_get('forum_containers', array());
+ foreach ($node->taxonomy as $term) {
+ if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
+ if (in_array($term, $containers)) {
+ $term = taxonomy_get_term($term);
+ form_set_error('taxonomy', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
+ }
+ }
+ }
+ }
}
/**
@@ -327,16 +352,15 @@ function forum_view(&$node, $teaser = FALSE, $page = FALSE) {
}
/**
- * Implementation of hook_submit().
- *
- * Check in particular that only a "leaf" term in the associated taxonomy
- * vocabulary is selected, not a "container" term.
+ * An early submit handler of the forum_node_form. Runs before the node is saved.
*/
-function forum_submit(&$node) {
+function forum_node_submit_early($form_id, &$node) {
+ $node = (object)$node;
+
// Make sure all fields are set properly:
$node->icon = $node->icon ? $node->icon : '';
- if ($node->taxonomy) {
+ if (!empty($node->taxonomy)) {
// Get the forum terms from the (cached) tree
$tree = taxonomy_get_tree(_forum_get_vid());
if ($tree) {
@@ -357,35 +381,13 @@ function forum_submit(&$node) {
}
}
}
-}
-/**
- * Implementation of hook_validate().
- *
- * Check in particular that only a "leaf" term in the associated taxonomy
- * vocabulary is selected, not a "container" term.
- */
-function forum_validate($node) {
- if ($node->taxonomy) {
- // Extract the node's proper topic ID.
- $vocabulary = variable_get('forum_nav_vocabulary', '');
- $containers = variable_get('forum_containers', array());
- foreach ($node->taxonomy as $term) {
- if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
- if (in_array($term, $containers)) {
- $term = taxonomy_get_term($term);
- form_set_error('taxonomy', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
- }
- }
- }
- }
+ $node = (array)$node;
}
-/**
- * Implementation of hook_update().
- */
-function forum_update($node) {
- if ($node->revision) {
+function forum_node_submit($form_id, $node) {
+ $node = (object)$node;
+ if ($node->is_new) {
db_query("INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)", $node->nid, $node->vid, $node->tid);
}
else {
@@ -424,18 +426,8 @@ function forum_prepare(&$node) {
}
}
-/**
- * Implementation of hook_insert().
- */
-function forum_insert($node) {
- db_query('INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->tid);
-}
-
-/**
- * Implementation of hook_delete().
- */
-function forum_delete(&$node) {
- db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
+function forum_node_delete_confirm_submit($form_id, $form_values) {
+ db_query('DELETE FROM {forum} WHERE nid = %d', $form_values['node']->nid);
}
/**