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.
This commit is contained in:
Eloy Lafuente (stronk7)
2019-05-19 10:42:59 +02:00
parent f6548dfbae
commit 743d66bfbd
+9 -3
View File
@@ -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);