From 743d66bfbdf6b5bb3f9aebffddffb80aabf53eec Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 18 May 2019 19:49:39 +0200 Subject: [PATCH] MDL-65635 forum: Small improvement to the advanced button 1) Always honor the preferred format (this is a new post). 2) Only perform the conversion to HTML when the preferred format is HTML. This way, users having HTML as format (because of their editor preference) will get the inline-reply converted to HTML and the editor displayed. And users not having HTML as format (because of their edito preference) will get the format set to their format (PLAIN, MOODLE or MARKDOWN) with the contents unmodified. Of course, if anybody is using a PLAIN, MOODLE or MARKDOWN editor... it will be displayed. --- mod/forum/post.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mod/forum/post.php b/mod/forum/post.php index bad66eb7e38..ec2fa052275 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -252,10 +252,15 @@ 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. + // We always are going to honor the preferred format. We are creating a new post. $preferredformat = editors_get_preferred_format(); - if ($preferredformat != $prefilledpostformat) { - $prefilledpost = format_text($prefilledpost, $prefilledpostformat, ['context' => $modcontext]); + + // Only if there are prefilled contents coming. + if (!empty($prefilledpost)) { + // If the prefilled post is not HTML and the preferred format is HTML, convert to it. + if ($prefilledpostformat != FORMAT_HTML and $preferredformat == FORMAT_HTML) { + $prefilledpost = format_text($prefilledpost, $prefilledpostformat, ['context' => $modcontext]); + } } // Load up the $post variable. @@ -268,6 +273,7 @@ if (!empty($forum)) { $post->userid = $USER->id; $post->parentpostauthor = $parent->userid; $post->message = $prefilledpost; + $post->messageformat = $preferredformat; $post->isprivatereply = $prefilledprivatereply; $canreplyprivately = $capabilitymanager->can_reply_privately_to_post($USER, $parententity);