MDL-65635 forum: Small improvement to the submit inline-reply

This commit mimics 100% the behavior achieved with the
parent commit of this when using the advance option.

1) Rename the 'tohtml' option to 'topreferredformat' to better
represent what it's doing.

2) Always honor the preferred format (this is a new post).

3) Only perform the conversion to HTML when the preferred format is
HTML.

That way any user, no matter thy are using format MOODLE (plain textbox),
MARKDOWN (marklar editor) or HTML (atto and tinymce editor) will
get always the format correct and the contents ready to be edited if
desired. HTML ones converted to HTML and TEXT ones unmodified.
This commit is contained in:
Eloy Lafuente (stronk7)
2019-05-19 10:42:59 +02:00
parent 743d66bfbd
commit 117e4bd40d
6 changed files with 23 additions and 17 deletions
+1 -1
View File
@@ -1 +1 @@
define(["core/ajax"],function(a){var b=function(b,c,d){var e={methodname:"mod_forum_set_subscription_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},c=function(b,c,d,e,f,g){var h={methodname:"mod_forum_add_discussion_post",args:{postid:b,message:d,messageformat:e,subject:c,options:[{name:"private",value:f},{name:"tohtml",value:g}]}};return a.call([h])[0]},d=function(b,c,d){var e={methodname:"mod_forum_toggle_favourite_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]},e=function(b,c,d){var e={methodname:"mod_forum_set_lock_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},f=function(b,c,d){var e={methodname:"mod_forum_set_pin_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]};return{setDiscussionSubscriptionState:b,addDiscussionPost:c,setDiscussionLockState:e,setFavouriteDiscussionState:d,setPinDiscussionState:f}});
define(["core/ajax"],function(a){var b=function(b,c,d){var e={methodname:"mod_forum_set_subscription_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},c=function(b,c,d,e,f,g){var h={methodname:"mod_forum_add_discussion_post",args:{postid:b,message:d,messageformat:e,subject:c,options:[{name:"private",value:f},{name:"topreferredformat",value:g}]}};return a.call([h])[0]},d=function(b,c,d){var e={methodname:"mod_forum_toggle_favourite_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]},e=function(b,c,d){var e={methodname:"mod_forum_set_lock_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},f=function(b,c,d){var e={methodname:"mod_forum_set_pin_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]};return{setDiscussionSubscriptionState:b,addDiscussionPost:c,setDiscussionLockState:e,setFavouriteDiscussionState:d,setPinDiscussionState:f}});
+2 -2
View File
@@ -94,7 +94,7 @@ define([
// In the future, other formats should be supported, letting users to use their preferred editor and format.
var messageformat = CONTENT_FORMATS.MOODLE;
// The message post will be converted from messageformat to FORMAT_HTML.
var tohtml = true;
var topreferredformat = true;
var postid = form.elements.reply.value;
var subject = form.elements.subject.value;
var currentRoot = submitButton.parents(Selectors.post.forumContent);
@@ -106,7 +106,7 @@ define([
showSubmitButtonLoadingIcon(submitButton);
allButtons.prop('disabled', true);
Repository.addDiscussionPost(postid, subject, message, messageformat, isprivatereply, tohtml)
Repository.addDiscussionPost(postid, subject, message, messageformat, isprivatereply, topreferredformat)
.then(function(context) {
var message = context.messages.reduce(function(carry, message) {
if (message.type == 'success') {
+3 -3
View File
@@ -43,7 +43,7 @@ define(['core/ajax'], function(Ajax) {
return Ajax.call([request])[0];
};
var addDiscussionPost = function(postid, subject, message, messageformat, isprivatereply, tohtml) {
var addDiscussionPost = function(postid, subject, message, messageformat, isprivatereply, topreferredformat) {
var request = {
methodname: 'mod_forum_add_discussion_post',
args: {
@@ -55,8 +55,8 @@ define(['core/ajax'], function(Ajax) {
name: "private",
value: isprivatereply,
}, {
name: "tohtml",
value: tohtml,
name: "topreferredformat",
value: topreferredformat,
}]
}
};
+12 -7
View File
@@ -1188,7 +1188,7 @@ class mod_forum_external extends external_api {
private (bool); make this reply private to the author of the parent post, default to false.
inlineattachmentsid (int); the draft file area id for inline attachments
attachmentsid (int); the draft file area id for attachments
tohtml (bool); convert the message & messageformat to FORMAT_HTML, defaults to false
topreferredformat (bool); convert the message & messageformat to FORMAT_HTML, defaults to false
'),
'value' => new external_value(PARAM_RAW, 'the value of the option,
this param is validated in the external function.'
@@ -1263,7 +1263,7 @@ class mod_forum_external extends external_api {
'private' => false,
'inlineattachmentsid' => 0,
'attachmentsid' => null,
'tohtml' => false
'topreferredformat' => false
);
foreach ($params['options'] as $option) {
$name = trim($option['name']);
@@ -1284,7 +1284,7 @@ class mod_forum_external extends external_api {
$value = 0;
}
break;
case 'tohtml':
case 'topreferredformat':
$value = clean_param($option['value'], PARAM_BOOL);
break;
default:
@@ -1300,10 +1300,15 @@ class mod_forum_external extends external_api {
$thresholdwarning = forum_check_throttling($forumrecord, $cm);
forum_check_blocking_threshold($thresholdwarning);
// If we want to force a conversion to HTML, let's do it now.
if ($options['tohtml'] && $params['messageformat'] != FORMAT_HTML) {
$params['message'] = format_text($params['message'], $params['messageformat'], ['context' => $context]);
$params['messageformat'] = FORMAT_HTML;
// If we want to force a conversion to the preferred format, let's do it now.
if ($options['topreferredformat']) {
// We always are going to honor the preferred format. We are creating a new post.
$preferredformat = editors_get_preferred_format();
// If the post is not HTML and the preferred format is HTML, convert to it.
if ($params['messageformat'] != FORMAT_HTML and $preferredformat == FORMAT_HTML) {
$params['message'] = format_text($params['message'], $params['messageformat'], ['context' => $context]);
}
$params['messageformat'] = $preferredformat;
}
// Create the post.
+4 -3
View File
@@ -1601,9 +1601,10 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$this->assertEquals($format, $dbformat);
}
// Now let's try the 'tohtml' option. That should end with the content
// transformed and the format being FORMAT_HTML always.
$options = [['name' => 'tohtml', 'value' => true]];
// Now let's try the 'topreferredformat' option. That should end with the content
// transformed and the format being FORMAT_HTML (when, like in this case, user preferred
// format is HTML, inferred from editor in preferences).
$options = [['name' => 'topreferredformat', 'value' => true]];
$createdpost = mod_forum_external::add_discussion_post($discussion->firstpost,
'interesting subject', 'with some https://example.com link', $options, FORMAT_MOODLE);
$createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
+1 -1
View File
@@ -14,7 +14,7 @@ information provided here is intended especially for developers.
* New external function mod_forum_external::get_forum_discussions returns a list of forum discussions optionally sorted and paginated.
* External function mod_forum_external::get_forum_discussions_paginated has been deprecated.
Use mod_forum_external::get_forum_discussions instead.
* External function mod_forum_external::add_discussion_post() has a new 'messageformat' param to be able to handle other formats different from FORMAT_HTML (that continues being the default one). Also a new 'tohtml' option enables the automatic conversion between any format and FORMAT_HTML before contents are saved.
* External function mod_forum_external::add_discussion_post() has a new 'messageformat' param to be able to handle other formats different from FORMAT_HTML (that continues being the default one). Also a new 'topreferredformat' option enables the automatic conversion between any format and the preferred format (given the editor preference) before contents are saved.
=== 3.6 ===