Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

by David Elliott -
Number of replies: 5
Hello! I work on the moodle plugin quickmail (lsu) and have gotten a complaint that the 'plain text' option doesn't work, and I have 'fixed' it a couple of times, but I'm now more confused than ever about what should be happening, conceptually. 


Does it make any sense to have moodle auto-format, HTML, and Markdown? For text that is leaving Moodle? For example, moodle auto-format wouldn't make the smiley faces in my email client anyway right?  -  https://docs.moodle.org/28/en/Formatting_text   -  I'm starting to think I shouldn't be using the 4-item drop down menu for the plain-text editor.  and instead should just make QM have a plain text option (and do that by just hiding the dropdown menu and having it set to plain-text), and an HTML option(TinyMC, or Atto). 


What's the quickest and most fail-safe way to create HTML from plaintext? and plaintext from HTML? And also, (email_to_user and format_text)

I'm a little unclear on what Moodle Core is doing for me and what I need to provide, prior to calling 'email_to_user', it seems like I need to make an HTML version and a text version and that is all. But theres a couple different 'format_text' functions, 1. format_text, and 2. format_text_email, but I don't think i want the email one based on a quick glance of code in other places. I think I've got format_text working for me kind of, but again am unsure about the 4 options of the plain-text editor. 

Any advice or guidance or suggestions would be appreciated. Quickmails or most used plugin and before I change some options for one complaint, I wanna be reasonably sure I won't get 400 complaints once I've changed it. smile


This post seems somewhat related -> https://moodle.org/mod/forum/discuss.php?d=269424&parent=1246844

Average of ratings: -
In reply to David Elliott

Re: Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

by Brendan Heywood -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

For example, moodle auto-format wouldn't make the smiley faces in my email client anyway right? 

Why not? This could work fine, and already is elsewhere.

Also that plugin doesn't have any unit tests at all so maybe start adding some first so you don't chase your tail on regressions (or dealing with support fallout). 

All of them should work and do something sensible, and all of this logic should be done by core for you if you use format_text() for all html output and format_text_email() for the plain text and send as dual mime type, which should also be handled for you.

Have a poke around the forum module cron code and see how it processes it, and aim to make it consistent with that, look for forum_make_mail_text() and forum_make_mail_html() in /mod/forum/lib.php around lines 1100-1200

My comments in that other forum are kinda unrelated and about the layout of the various emails that moodle sends, this should be something that can be customised in a theme and shouldn't need hacking core code to achieve that.

Have fun smile 

Average of ratings: Useful (1)
In reply to Brendan Heywood

Re: Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

by David Elliott -

Thanks! That cleared up which direction to go. We have some unit tests elsewhere, and are working on Behat tests. Hoping to learn something at the dev meeting tonight. 

In reply to Brendan Heywood

Re: Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

by David Elliott -

On line 762 of lib.php in the forum code, it seems like this code is doing what I suggested for quickmail and just using plain_text 

                $eventdata->fullmessageformat = FORMAT_PLAIN;

I don't see anywhere where, the message is being handled differently based on the text editor settings. It seems forum_make_mail_text is expecting and delivering plain text, and then the eventdata is also passing that format prior to actually being sent.


I also can't seem to get the smileys working for moodle auto-format in the forum. 

In reply to David Elliott

Re: Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

by David Elliott -

I disagree with part of that last reply. I can see where and when and why format_text and format_text_html are being used inside the forum_make_mail_text and _html functions. But I am still confused as to why eventdata is setting the format that way. 



In reply to David Elliott

Re: Formatting Text, and email_to_user, and format_text, and format_text_email, Quickmail

by Brendan Heywood -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It's to avoid double processing, the bit that counts is forum_make_mail_post() which calls format_text() with the type of input that was up to the author to decide $post->messageformat . This then gets passed into the event data using FORMAT_PLAIN so it doesn't get processed a second time.

Re smilies check what filters are turned on /admin/filters.php see:

https://docs.moodle.org/28/en/Display_emoticons_as_images_filter


Average of ratings: Useful (1)