From f6548dfbaefd0d8d514501bd8264bd11e784b086 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Fri, 17 May 2019 21:39:57 +0200 Subject: [PATCH] MDL-65635 forum: convert inline reply format when opening the advanced When a inline reply post is written and the user changes to the advanced edition, the post format has to be converted from FORMAT_MOODLE. --- mod/forum/amd/build/posts_list.min.js | 2 +- mod/forum/amd/src/posts_list.js | 3 ++- mod/forum/post.php | 7 +++++++ mod/forum/templates/inpage_reply.mustache | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mod/forum/amd/build/posts_list.min.js b/mod/forum/amd/build/posts_list.min.js index 644a0042e9f..df43413cab2 100644 --- a/mod/forum/amd/build/posts_list.min.js +++ b/mod/forum/amd/build/posts_list.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/notification","mod_forum/selectors","mod_forum/inpage_reply"],function(a,b,c,d,e){var f=function(e){e.on("click",d.post.inpageReplyLink,function(e){if(e.preventDefault(),window.location.hash){var f=window.location.href.split("#")[0];history.pushState({},document.title,f)}var g=a(e.currentTarget).parents(d.post.forumCoreContent),h=g.find(d.post.forumSubject),i=a(e.currentTarget).parents(d.post.forumContent),j={postid:a(i).data("post-id"),reply_url:a(e.currentTarget).attr("href"),sesskey:M.cfg.sesskey,parentsubject:h.html(),canreplyprivately:a(e.currentTarget).data("can-reply-privately")};if(i.find(d.post.inpageReplyContent).length){var k=i.find(d.post.inpageReplyContent);k.slideToggle(300),k.is(":visible")&&k.find("textarea").focus()}else b.render("mod_forum/inpage_reply",j).then(function(a,c){return b.appendNodeContents(g,a,c)}).then(function(){return i.find(d.post.inpageReplyContent).slideToggle(300).find("textarea").focus()}).fail(c.exception)})};return{init:function(a){f(a),e.init(a)}}}); \ No newline at end of file +define(["jquery","core/templates","core/notification","mod_forum/selectors","mod_forum/inpage_reply"],function(a,b,c,d,e){var f=function(f){f.on("click",d.post.inpageReplyLink,function(f){if(f.preventDefault(),window.location.hash){var g=window.location.href.split("#")[0];history.pushState({},document.title,g)}var h=a(f.currentTarget).parents(d.post.forumCoreContent),i=h.find(d.post.forumSubject),j=a(f.currentTarget).parents(d.post.forumContent),k={postid:a(j).data("post-id"),reply_url:a(f.currentTarget).attr("href"),sesskey:M.cfg.sesskey,parentsubject:i.html(),canreplyprivately:a(f.currentTarget).data("can-reply-privately"),postformat:e.CONTENT_FORMATS.MOODLE};if(j.find(d.post.inpageReplyContent).length){var l=j.find(d.post.inpageReplyContent);l.slideToggle(300),l.is(":visible")&&l.find("textarea").focus()}else b.render("mod_forum/inpage_reply",k).then(function(a,c){return b.appendNodeContents(h,a,c)}).then(function(){return j.find(d.post.inpageReplyContent).slideToggle(300).find("textarea").focus()}).fail(c.exception)})};return{init:function(a){f(a),e.init(a)}}}); \ No newline at end of file diff --git a/mod/forum/amd/src/posts_list.js b/mod/forum/amd/src/posts_list.js index e68c87e9024..5e24d7a5baf 100644 --- a/mod/forum/amd/src/posts_list.js +++ b/mod/forum/amd/src/posts_list.js @@ -60,7 +60,8 @@ define([ "reply_url": $(e.currentTarget).attr('href'), sesskey: M.cfg.sesskey, parentsubject: currentSubject.html(), - canreplyprivately: $(e.currentTarget).data('can-reply-privately') + canreplyprivately: $(e.currentTarget).data('can-reply-privately'), + postformat: InPageReply.CONTENT_FORMATS.MOODLE }; if (!currentRoot.find(Selectors.post.inpageReplyContent).length) { diff --git a/mod/forum/post.php b/mod/forum/post.php index a9105f8362d..bad66eb7e38 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -36,6 +36,7 @@ $confirm = optional_param('confirm', 0, PARAM_INT); $groupid = optional_param('groupid', null, PARAM_INT); $subject = optional_param('subject', '', PARAM_TEXT); $prefilledpost = optional_param('post', '', PARAM_TEXT); +$prefilledpostformat = optional_param('postformat', FORMAT_MOODLE, PARAM_INT); $prefilledprivatereply = optional_param('privatereply', false, PARAM_BOOL); $PAGE->set_url('/mod/forum/post.php', array( @@ -251,6 +252,12 @@ if (!empty($forum)) { print_error('cannotreplytoprivatereply', 'forum'); } + // If the prefilled post is sent using a different format to the preferred by the user, convert it. + $preferredformat = editors_get_preferred_format(); + if ($preferredformat != $prefilledpostformat) { + $prefilledpost = format_text($prefilledpost, $prefilledpostformat, ['context' => $modcontext]); + } + // Load up the $post variable. $post = new stdClass(); $post->course = $course->id; diff --git a/mod/forum/templates/inpage_reply.mustache b/mod/forum/templates/inpage_reply.mustache index dcc175c365f..8a99d1d356d 100644 --- a/mod/forum/templates/inpage_reply.mustache +++ b/mod/forum/templates/inpage_reply.mustache @@ -39,6 +39,7 @@
+