Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.546
diff -u -p -r1.546 forum.module
--- modules/forum/forum.module	26 Dec 2009 16:50:09 -0000	1.546
+++ modules/forum/forum.module	26 Dec 2009 20:49:27 -0000
@@ -256,18 +256,6 @@ function forum_node_view($node, $view_mo
 }
 
 /**
- * Implements hook_node_prepare().
- */
-function forum_node_prepare($node) {
-  if (_forum_node_check_node_type($node)) {
-    if (empty($node->nid)) {
-      // New topic
-      $node->taxonomy_forums[0]['tid'] =  arg(3);
-    }
-  }
-}
-
-/**
  * Implements hook_node_validate().
  *
  * Check in particular that only a "leaf" term in the associated taxonomy.
@@ -578,6 +566,13 @@ function forum_form_alter(&$form, $form_
     // Make the vocabulary required for 'real' forum-nodes.
     $form['taxonomy_forums'][$langcode]['#required'] = TRUE;
     $form['taxonomy_forums'][$langcode]['#multiple'] = FALSE;
+    if (empty($form['taxonomy_forums'][$langcode]['#default_value'])) {
+      // If there is no default forum already selected, try to get the forum
+      // ID from the URL (e.g., if we are on a page like node/add/forum/3, we
+      // expect "3" to be the ID of the forum that was requested).
+      $requested_forum_id = arg(3);
+      $form['taxonomy_forums'][$langcode]['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : NULL;
+    }
   }
 }
 
Index: modules/forum/forum.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.test,v
retrieving revision 1.43
diff -u -p -r1.43 forum.test
--- modules/forum/forum.test	2 Dec 2009 19:26:22 -0000	1.43
+++ modules/forum/forum.test	26 Dec 2009 20:49:27 -0000
@@ -258,24 +258,14 @@ class ForumTestCase extends DrupalWebTes
     // Generate a random subject/body.
     $title = $this->randomName(20);
     $body = $this->randomName(200);
-
-    // Without this being set, post variable equals the first non-blank in
-    // select items list.
-    $tid = $forum['tid'];
-
     $langcode = LANGUAGE_NONE;
     $edit = array(
       "title[$langcode][0][value]" => $title,
       "body[$langcode][0][value]" => $body,
-      "taxonomy_forums[$langcode]" => $tid,
     );
 
-    // TODO The taxonomy select value is set by drupal code when the tid is part
-    // of the url. However, unless a tid is passed in the edit array, when
-    // drupalPost() runs, the select value is not preserved. Instead, the post
-    // variables seem to pick up the first non-blank value in the select list.
-    // Create forum topic.
-    $this->drupalPost('node/add/forum/', $edit, t('Save'));
+    // Create the forum topic, preselecting the forum ID via a URL parameter.
+    $this->drupalPost('node/add/forum/' . $forum['tid'], $edit, t('Save'));
     $type = t('Forum topic');
     if ($container) {
       $this->assertNoRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), t('Forum topic was not created'));
