Commit d058394c authored by Dries's avatar Dries

- Patch #652176 by bleen18, David_Rothstein, JacobSingh: fixed 'Forums' term defaulting to 'None'.

parent 76a4f8fe
......@@ -255,18 +255,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().
*
......@@ -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;
}
}
}
......
......@@ -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);
......
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