Skip to content

Commit

Permalink
improve the message block of the post form (#182)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
TamaroWalter and NinaHerrmann authored Jul 12, 2024
1 parent 3032b86 commit cb7a212
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
22 changes: 21 additions & 1 deletion classes/post_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function definition() {
$modform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');

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

Expand Down Expand Up @@ -141,6 +142,25 @@ public static function attachment_options($moodleoverflow) {
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
];
}

/**
* Returns the options array to use in forum text editor
*
* @param context_module $context
* @param int $postid post id, use null when adding new post
* @return array
*/
public static function editor_options(context_module $context, $postid) {
global $COURSE, $PAGE, $CFG;
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
return [
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $maxbytes,
'trusttext' => true,
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid),
];
}
}


Expand Down
5 changes: 4 additions & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

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

global $CFG;
require_once(dirname(__FILE__) . '/lib.php');
require_once($CFG->libdir . '/portfoliolib.php');

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

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

// Load the attachments.
$mustachedata->attachments = get_attachments($post, $cm);
Expand Down
2 changes: 1 addition & 1 deletion templates/post.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<br>
{{/image}}
{{^image}}
<a href="{{filepath}}">
<a class="icon-size-6" href="{{filepath}}">
{{{icon}}}
</a>
<a href="{{filepath}}">
Expand Down

0 comments on commit cb7a212

Please sign in to comment.