From 0ad37ad057018eeed7a0734b98bda273f5f30aae Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Wed, 14 Apr 2010 15:51:21 +0000 Subject: #652372 by matason, ksenzee, naxoc, jpmckinney, sun: Don't allow users to add forum topics when no forums exist. --- modules/forum/forum.install | 1 + modules/forum/forum.module | 8 +++++++- modules/forum/forum.test | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/forum/forum.install b/modules/forum/forum.install index 5c4957cbb..7e6de833a 100644 --- a/modules/forum/forum.install +++ b/modules/forum/forum.install @@ -58,6 +58,7 @@ function forum_enable() { 'entity_type' => 'node', 'label' => $vocabulary->name, 'bundle' => 'forum', + 'required' => TRUE, 'widget' => array( 'type' => 'options_select', ), diff --git a/modules/forum/forum.module b/modules/forum/forum.module index c278c946b..10d55b1a3 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -299,7 +299,13 @@ function forum_node_validate($node, $form) { if (!empty($node->taxonomy_forums[$langcode])) { // Extract the node's proper topic ID. $containers = variable_get('forum_containers', array()); - foreach ($node->taxonomy_forums[$langcode] as $item) { + foreach ($node->taxonomy_forums[$langcode] as $delta => $item) { + // If no term was selected (e.g. when no terms exist yet), remove the + // item. + if (empty($item['tid'])) { + unset($node->taxonomy_forums[$langcode][$delta]); + continue; + } $term = taxonomy_term_load($item['tid']); $used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid',0 , 1, array( ':tid' => $term->tid, diff --git a/modules/forum/forum.test b/modules/forum/forum.test index f485e48d4..d91664259 100644 --- a/modules/forum/forum.test +++ b/modules/forum/forum.test @@ -90,6 +90,17 @@ class ForumTestCase extends DrupalWebTestCase { $this->assertResponse(200); } + /** + * Forum nodes should not be created without choosing forum from select list. + */ + function testAddOrphanTopic() { + $this->drupalLogin($this->admin_user); + $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NONE .'][0][value]' => $this->randomName(120)), t('Save')); + + $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField(); + $this->assertEqual(0, $nid_count, t('A forum node was not created.')); + } + /** * Run admin tests on the admin user. * -- cgit v1.2.3