Commit b8264306 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#176282 by Desbeers: forum taxonomy was required for non-forum node types,...

#176282 by Desbeers: forum taxonomy was required for non-forum node types, when enabled for forum inclusion
parent c073e88c
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
function forum_install() { function forum_install() {
// Create tables. // Create tables.
drupal_install_schema('forum'); drupal_install_schema('forum');
// Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
db_query("UPDATE {system} SET weight = 1 WHERE name = 'forum'");
} }
function forum_enable() { function forum_enable() {
...@@ -19,7 +21,7 @@ function forum_enable() { ...@@ -19,7 +21,7 @@ function forum_enable() {
$vocabulary = array( $vocabulary = array(
'name' => t('Forums'), 'name' => t('Forums'),
'multiple' => 0, 'multiple' => 0,
'required' => 1, 'required' => 0,
'hierarchy' => 1, 'hierarchy' => 1,
'relations' => 0, 'relations' => 0,
'module' => 'forum', 'module' => 'forum',
......
...@@ -78,10 +78,6 @@ function forum_term_load($tid) { ...@@ -78,10 +78,6 @@ function forum_term_load($tid) {
* Implementation of hook_menu(). * Implementation of hook_menu().
*/ */
function forum_menu() { function forum_menu() {
$items['node/add/forum'] = array(
'title' => 'Forum topic',
'access arguments' => array('create forum topics'),
);
$items['forum'] = array( $items['forum'] = array(
'title' => 'Forums', 'title' => 'Forums',
'page callback' => 'forum_page', 'page callback' => 'forum_page',
...@@ -171,13 +167,10 @@ function forum_nodeapi(&$node, $op, $teaser, $page) { ...@@ -171,13 +167,10 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) { switch ($op) {
case 'view': case 'view':
if ($page && $node->taxonomy) { if ($page && taxonomy_node_get_terms_by_vocabulary($node, $vid) && $tree = taxonomy_get_tree($vid)) {
// Get the forum terms from the (cached) tree // Get the forum terms from the (cached) tree
$tree = taxonomy_get_tree($vid); foreach ($tree as $term) {
if ($tree) { $forum_terms[] = $term->tid;
foreach ($tree as $term) {
$forum_terms[] = $term->tid;
}
} }
foreach ($node->taxonomy as $term_id => $term) { foreach ($node->taxonomy as $term_id => $term) {
if (in_array($term_id, $forum_terms)) { if (in_array($term_id, $forum_terms)) {
...@@ -202,7 +195,6 @@ function forum_nodeapi(&$node, $op, $teaser, $page) { ...@@ -202,7 +195,6 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
); );
} }
} }
return $node;
break; break;
case 'prepare': case 'prepare':
...@@ -211,7 +203,6 @@ function forum_nodeapi(&$node, $op, $teaser, $page) { ...@@ -211,7 +203,6 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
$node->taxonomy[arg(3)]->vid = $vid; $node->taxonomy[arg(3)]->vid = $vid;
$node->taxonomy[arg(3)]->tid = arg(3); $node->taxonomy[arg(3)]->tid = arg(3);
} }
return $node;
break; break;
// Check in particular that only a "leaf" term in the associated taxonomy // Check in particular that only a "leaf" term in the associated taxonomy
...@@ -237,13 +228,10 @@ function forum_nodeapi(&$node, $op, $teaser, $page) { ...@@ -237,13 +228,10 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
// Make sure all fields are set properly: // Make sure all fields are set properly:
$node->icon = !empty($node->icon) ? $node->icon : ''; $node->icon = !empty($node->icon) ? $node->icon : '';
if ($node->taxonomy) { if ($node->taxonomy && $tree = taxonomy_get_tree($vid)) {
// Get the forum terms from the (cached) tree // Get the forum terms from the (cached) tree if we have a taxonomy.
$tree = taxonomy_get_tree($vid); foreach ($tree as $term) {
if ($tree) { $forum_terms[] = $term->tid;
foreach ($tree as $term) {
$forum_terms[] = $term->tid;
}
} }
foreach ($node->taxonomy as $term_id) { foreach ($node->taxonomy as $term_id) {
if (in_array($term_id, $forum_terms)) { if (in_array($term_id, $forum_terms)) {
...@@ -251,26 +239,36 @@ function forum_nodeapi(&$node, $op, $teaser, $page) { ...@@ -251,26 +239,36 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
} }
} }
$old_tid = db_result(db_query_range("SELECT t.tid FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.nid = %d ORDER BY t.vid DESC", $node->nid, 0, 1)); $old_tid = db_result(db_query_range("SELECT t.tid FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.nid = %d ORDER BY t.vid DESC", $node->nid, 0, 1));
if ($old_tid) { if ($old_tid && isset($node->tid) && ($node->tid != $old_tid) && !empty($node->shadow)) {
if (($node->tid != $old_tid) && $node->shadow) { // A shadow copy needs to be created. Retain new term and add old term.
// A shadow copy needs to be created. Retain new term and add old term. $node->taxonomy[] = $old_tid;
$node->taxonomy[] = $old_tid;
}
} }
} }
break; break;
case 'update': case 'update':
if (!$node->revision) { if (!$node->revision && db_result(db_query('SELECT tid FROM {forum} WHERE nid=%d', $node->nid))) {
db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid); if (!empty($node->tid)) {
db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid);
}
// The node is removed from the forum.
else {
db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
}
break; break;
} }
// Deliberate no break -- for new revisions we need an insert. // Deliberate no break -- for new revisions and for previously unassigned terms we need an insert.
case 'insert': case 'insert':
db_query('INSERT INTO {forum} (tid, vid, nid) VALUES (%d, %d, %d)', $node->tid, $node->vid, $node->nid); if (!empty($node->tid)) {
db_query('INSERT INTO {forum} (tid, vid, nid) VALUES (%d, %d, %d)', $node->tid, $node->vid, $node->nid);
}
break; break;
case 'delete': case 'delete':
db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid); db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
break; break;
case 'load': case 'load':
return db_fetch_array(db_query('SELECT tid AS forum_tid FROM {forum} WHERE vid = %d', $node->vid)); return db_fetch_array(db_query('SELECT tid AS forum_tid FROM {forum} WHERE vid = %d', $node->vid));
} }
...@@ -355,17 +353,23 @@ function forum_form_alter(&$form, $form_state, $form_id) { ...@@ -355,17 +353,23 @@ function forum_form_alter(&$form, $form_state, $form_id) {
); );
$form['nodes']['#required'] = TRUE; $form['nodes']['#required'] = TRUE;
$form['hierarchy'] = array('#type' => 'value', '#value' => 1); $form['hierarchy'] = array('#type' => 'value', '#value' => 1);
unset($form['settings']['relations']); $form['settings']['required'] = array('#type' => 'value', '#value' => FALSE);
unset($form['settings']['tags']); $form['settings']['relations'] = array('#type' => 'value', '#value' => FALSE);
unset($form['settings']['multiple']); $form['settings']['tags'] = array('#type' => 'value', '#value' => FALSE);
unset($form['delete']); $form['settings']['multiple'] = array('#type' => 'value', '#value' => FALSE);
$form['settings']['required'] = array('#type' => 'value', '#value' => 1); unset($form['delete']);
} }
} }
// Hide multiple parents select from forum terms. // Hide multiple parents select from forum terms.
if ($form_id == 'taxonomy_form_term') { if ($form_id == 'taxonomy_form_term') {
unset($form['advanced']['parent']); unset($form['advanced']['parent']);
} }
if ($form_id == 'forum_node_form') {
// Make the vocabulary required for 'real' forum-nodes.
$vid = variable_get('forum_nav_vocabulary', '');
$form['taxonomy'][$vid]['#required'] = TRUE;
$form['taxonomy'][$vid]['#options'][''] = t('- Please choose -');
}
} }
/** /**
......
...@@ -2713,6 +2713,20 @@ function system_update_6040() { ...@@ -2713,6 +2713,20 @@ function system_update_6040() {
return $ret; return $ret;
} }
/**
* Change forum vocabulary not to be required by default and set the weight of the forum.module 1 higher than the taxonomy.module.
*/
function system_update_6041() {
$weight = intval((db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"))) + 1);
$ret = array();
$vid = intval(variable_get('forum_nav_vocabulary', ''));
if (db_table_exists('vocabulary') && $vid) {
$ret[] = update_sql("UPDATE {vocabulary} SET required = 0 WHERE vid = " . $vid);
$ret[] = update_sql("UPDATE {system} SET weight = ". $weight ." WHERE name = 'forum'");
}
return $ret;
}
/** /**
* @} End of "defgroup updates-5.x-to-6.x" * @} End of "defgroup updates-5.x-to-6.x"
* The next series of updates should start at 7000. * The next series of updates should start at 7000.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment