MDL-814 forum: provide cancel button when posting
authorDan Poltawski <dan@moodle.com>
Mon, 27 Oct 2014 16:24:57 +0000 (16:24 +0000)
committerDan Poltawski <dan@moodle.com>
Mon, 27 Oct 2014 16:44:47 +0000 (16:44 +0000)
This is the way to clear atto drafts

mod/forum/classes/post_form.php
mod/forum/post.php

index 1e76e93..01a10bf 100644 (file)
@@ -201,7 +201,7 @@ class mod_forum_post_form extends moodleform {
         } else {
             $submit_string = get_string('posttoforum', 'forum');
         }
-        $this->add_action_buttons(false, $submit_string);
+        $this->add_action_buttons(true, $submit_string);
 
         $mform->addElement('hidden', 'course');
         $mform->setType('course', PARAM_INT);
index b1bdd9f..e53136e 100644 (file)
@@ -655,7 +655,14 @@ $mform_post->set_data(array(        'attachments'=>$draftitemid,
                                     array('discussion'=>$discussion->id):
                                     array()));
 
-if ($fromform = $mform_post->get_data()) {
+if ($mform_post->is_cancelled()) {
+    if (!isset($discussion->id) || $forum->type === 'qanda') {
+        // Q and A forums don't have a discussion page, so treat them like a new thread..
+        redirect(new moodle_url('/mod/forum/view.php', array('f' => $forum->id)));
+    } else {
+        redirect(new moodle_url('/mod/forum/discuss.php', array('d' => $discussion->id)));
+    }
+} else if ($fromform = $mform_post->get_data()) {
 
     if (empty($SESSION->fromurl)) {
         $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";