summaryrefslogtreecommitdiff
path: root/modules/forum
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-05 13:36:35 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-05 13:36:35 +0000
commitd058394cf373ca3529ff169db148478fa30aa414 (patch)
tree08bb63dc00cc5c0d7210c05922e8e175b1552d8e /modules/forum
parent76a4f8fe18360e9dc669fe0cdb1dfc8f9230fb2d (diff)
downloadbrdo-d058394cf373ca3529ff169db148478fa30aa414.tar.gz
brdo-d058394cf373ca3529ff169db148478fa30aa414.tar.bz2
- Patch #652176 by bleen18, David_Rothstein, JacobSingh: fixed 'Forums' term defaulting to 'None'.
Diffstat (limited to 'modules/forum')
-rw-r--r--modules/forum/forum.module19
-rw-r--r--modules/forum/forum.test17
2 files changed, 12 insertions, 24 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index e21217204..ae6648372 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -256,18 +256,6 @@ function forum_node_view($node, $view_mode) {
}
/**
- * 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_state, $form_id) {
// 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;
+ }
}
}
diff --git a/modules/forum/forum.test b/modules/forum/forum.test
index 4b673b707..64fcc7ade 100644
--- a/modules/forum/forum.test
+++ b/modules/forum/forum.test
@@ -261,23 +261,15 @@ class ForumTestCase extends DrupalWebTestCase {
$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" => $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'));
@@ -289,9 +281,10 @@ class ForumTestCase extends DrupalWebTestCase {
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), t('No error message was shown'));
}
- // Retrieve node object.
+ // Retrieve node object, ensure that the topic was created and in the proper forum.
$node = $this->drupalGetNodeByTitle($title);
$this->assertTrue($node != NULL, t('Node @title was loaded', array('@title' => $title)));
+ $this->assertEqual($node->taxonomy_forums[LANGUAGE_NONE][0]['tid'], $forum['tid'], 'Saved forum topic was in the expected forum');
// View forum topic.
$this->drupalGet('node/' . $node->nid);