Skip to content

Commit 9eeeb29

Browse files
committed
improve the message block of the post form
1 parent a385554 commit 9eeeb29

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
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 array(
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

0 commit comments

Comments
 (0)