diff options
Diffstat (limited to 'modules/forum')
-rw-r--r-- | modules/forum/forum.module | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 1ebc7175c..685c96a2f 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -231,31 +231,6 @@ 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))); - } - } - } - } } /** @@ -350,15 +325,16 @@ function forum_view(&$node, $teaser = FALSE, $page = FALSE) { } /** - * An early submit handler of the forum_node_form. Runs before the node is saved. + * Implementation of hook_submit(). + * + * Check in particular that only a "leaf" term in the associated taxonomy + * vocabulary is selected, not a "container" term. */ -function forum_node_submit_early($form_id, &$node) { - $node = (object)$node; - +function forum_submit(&$node) { // Make sure all fields are set properly: $node->icon = $node->icon ? $node->icon : ''; - if (!empty($node->taxonomy)) { + if ($node->taxonomy) { // Get the forum terms from the (cached) tree $tree = taxonomy_get_tree(_forum_get_vid()); if ($tree) { @@ -379,13 +355,35 @@ function forum_node_submit_early($form_id, &$node) { } } } +} - $node = (array)$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))); + } + } + } + } } -function forum_node_submit($form_id, $node) { - $node = (object)$node; - if ($node->is_new) { +/** + * Implementation of hook_update(). + */ +function forum_update($node) { + if ($node->revision) { db_query("INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)", $node->nid, $node->vid, $node->tid); } else { @@ -424,8 +422,18 @@ function forum_prepare(&$node) { } } -function forum_node_delete_confirm_submit($form_id, $form_values) { - db_query('DELETE FROM {forum} WHERE nid = %d', $form_values['node']->nid); +/** + * 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); } /** |