Skip to content

Commit cb7a212

Browse files
improve the message block of the post form (#182)
* improve the message block of the post form * pull from update branch * image and attachments shown correctly * increase version number for new feature * right version for new feature --------- Co-authored-by: Nina Herrmann <[email protected]>
1 parent 3032b86 commit cb7a212

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

classes/post_form.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function definition() {
5858
$modform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
5959

6060
// The message.
61-
$modform->addElement('editor', 'message', get_string('message', 'moodleoverflow'), null);
61+
$modform->addElement('editor', 'message', get_string('message', 'moodleoverflow'), null,
62+
self::editor_options($modcontext, (empty($post->id) ? null : $post->id)));
6263
$modform->setType('message', PARAM_RAW);
6364
$modform->addRule('message', get_string('required'), 'required', null, 'client');
6465

@@ -141,6 +142,25 @@ public static function attachment_options($moodleoverflow) {
141142
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
142143
];
143144
}
145+
146+
/**
147+
* Returns the options array to use in forum text editor
148+
*
149+
* @param context_module $context
150+
* @param int $postid post id, use null when adding new post
151+
* @return array
152+
*/
153+
public static function editor_options(context_module $context, $postid) {
154+
global $COURSE, $PAGE, $CFG;
155+
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
156+
return [
157+
'maxfiles' => EDITOR_UNLIMITED_FILES,
158+
'maxbytes' => $maxbytes,
159+
'trusttext' => true,
160+
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
161+
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid),
162+
];
163+
}
144164
}
145165

146166

locallib.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
defined('MOODLE_INTERNAL') || die();
3434

35+
global $CFG;
3536
require_once(dirname(__FILE__) . '/lib.php');
37+
require_once($CFG->libdir . '/portfoliolib.php');
3638

3739
/**
3840
* Get all discussions in a moodleoverflow instance.
@@ -1449,7 +1451,8 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co
14491451
$mustachedata->withinreviewperiod = $reviewable;
14501452

14511453
// Prepare the post.
1452-
$mustachedata->postcontent = format_text($post->message, $post->messageformat, ['context' => $modulecontext]);
1454+
$options = (array) portfolio_format_text_options() + ['context' => $modulecontext];
1455+
$mustachedata->postcontent = format_text($post->message, $post->messageformat, $options);
14531456

14541457
// Load the attachments.
14551458
$mustachedata->attachments = get_attachments($post, $cm);

templates/post.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<br>
7878
{{/image}}
7979
{{^image}}
80-
<a href="{{filepath}}">
80+
<a class="icon-size-6" href="{{filepath}}">
8181
{{{icon}}}
8282
</a>
8383
<a href="{{filepath}}">

0 commit comments

Comments
 (0)