HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Cannot get Rich Editor to work in embedded comments

I have a fresh 3.1 Vanilla Forums installation. I've enabled Rich Editor plugin and embedded my comments using the Universal Comment Embed Code.

When I post to a discussion through the normal Forum UI everything works. However, when I try to post normal text via embedded comments I always get the "Warning There was an error rendering this rich post." error.

Is it possible to use embedded comments if Rich Editor is enabled?

Also, can I somehow enable Rich Editor features (bolding, italic, picture adding, etc.) in embedded comments posting?

Comments

  • Options

    I believe I've found the issue. In vanilla/controllers/class.postcontroller.php there's a switch case clause for embedded comments (line number 627). The only available case, however, seems to be 'Wysiwyg', while the data posted from my embedded comments is 'Rich'.

    Is there a way to override or catch an event related to this? I couldn't find an event to listen to and this method, comment(), isn't one of the easily overridable functions handled here https://docs.vanillaforums.com/developer/addons/function-overrides/.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    What you describe sounds like an issue that should be reported on GitHub.

    I have taken a look at the line that you think might cause the trouble, but that code snippet is not responsible for the problem. It just transforms like breaks

  • Options

    Above the code snippet is a comment:

    "Special care is taken for embedded comments. Since we don't currently use an advanced editor for these comments, we may need to apply certain filters and fixes to the data to maintain its intended display with the input format (e.g. maintaining newlines)."

    Which makes me assume most if not all fixes needed for embedded comments should be placed under the if ($isEmbeddedComments) clause. Is this not true?

    Since I'm using Rich Editor the value for $inputFormatter in my case is "Rich". When a comment is posted from embedded comments the body is just plain text, e.g. "This is my message". But as the $inputFormatter is Rich the text should be saved in Rich format, which to my understanding would be something like [{"insert":"This is my message\n"}] (posting from embedded comments actually works if I try posting [{"insert":"This is my message"}] from the comments box).

    Can I edit this code via a custom plugin? Can I override that particular method (comment()) or override the entire controller in a clean, easy way?

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    If I understand it right the problem is as such:

    • The format for new posts is "Rich"
    • In embedded comments, the editor is not used
    • The "Rich" format doesn't accept simple text input

    The real problem is when you write a comment without the rich editor and the format is set to "Rich".

    So this should be avoided. I admit I was wrong with my assumption and the lines that you found could be used for changing the problem.

    I thought on how to make the rich editor work and that wouldn't be the right place for that.

    I do not know what is needed to make the rich editor work on embedded comments, but I have an idea for an approach. For offering a solution I would have to set up embedded comments somehow and I never did that.

    You can find the following event fired just before the lines you have cited:

                   $this->EventArguments['Discussion'] =& $EmbeddedDiscussionData;
                   $this->fireEvent('BeforeEmbedDiscussion');
    

    By hooking into that event you should be able to

    1. Check if format is "Rich" (if not return, all good)
    2. Try to format the Body as rich text
    3. If that fails: change Format to e.g. Markdown
    4. If it succeeds return happily


  • Options

    The BeforeEmbedDiscussion event is never called, because it is inside an if clause that checks the condition (!$Discussion && $isEmbeddedComments), and $Discussion exists. But thanks for the suggestion!

    I found another event I'm able to catch. I'm now using this inside my plugin in case anyone is trying to solve the same issue:

    public function PostController_comment_before($arg1, $arg2) {
        if ($_REQUEST["Embedded"] === "true" && $_REQUEST["Type"] === "Post" && c('Garden.InputFormatter') === 'Rich') {
            $body = $_REQUEST["Body"];
            if (isset($body)) {
                // change body's format to rich
            }
        }
    }
    

    Any idea when we can get a Rich Editor for embedded comments? 😅

  • Options
    charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff

    Hmm. I feel like we had fixed this some time ago. I'll go digging and see if I can figure out what happened here.

  • Options

    Hmm, I just noticed that when I have Rich Editor enabled and when I use the Universal Comment Embed Code I cannot use any Rich Editor functionalities in the comments box and the text isn't saved in Rich format to the database.

    BUT if I edit a previously sent comment I get to use Rich Editor. So, I can use Rich Editor in embedded comments but only if I edit an existing message.

  • Options
    charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff
    edited August 2019

    I did find this comment where we enabled using the formatter set in the dashboard for embedded comments. This looks like it was for 3.0 though.

    @kvaakvaak What Vanilla version are your running? Nevermind I see you specified 3.1. Could you file a new issue on our issue tracker?

  • Options
    charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff

    If you ignore the shoddy styling, I have rich editor functioning properly in my embedded comments on the latest version in my test embed site:


  • Options

    @charrondev Alright, that pic you posted made me doubt myself and I re-installed Vanilla 3.1 with a new database and everything, and the embedded comments script seems to work just fine.

    I must have messed up my previous fresh installation somehow. Sorry about wasting everyone's time... 😥

Sign In or Register to comment.