XF 2.2 Editor Preview BbCode

Taylor J

Well-known member
For the blog addon I've found time to work on again I currently have a "editing" page that is really just the editor on a page with a title input, pretty much a post-thread action without all of the extra stuff like thread types and a few others.

I currently have the below function for the preview action that i ripped from conversations/post-thread/etc but so far nothing happens when I click on preview in the editor.
PHP:
public function actionBlogAddPreview(ParameterBag $params)
    {
        $message = $this->plugin('XF:Editor')->fromInput('message');
        return $this->plugin('XF:BbCodePreview')->actionPreview(
            $message, 'blog-post', \XF::visitor()
        );
    }
and template code

HTML:
<xf:title>Create a new blog post</xf:title>
<div class="block">
    <div class="block-container">
        <div class="block-body">
            <xf:textboxrow name="title" value="{$title}" rowtype="fullWidth noLabel" class="input--title"
                maxlength="40"
                placeholder="{{ phrase('title...') }}"
                label="{{ phrase('title') }}" />

            <xf:editorrow name="message"
                value=""
                attachments="{{ $attachmentData ? $attachmentData.attachments : [] }}"
                rowtype="fullWidth noLabel mergePrev"
                data-preview-url="{{ link('userblogs/blog/add-preview', $blogPost) }}" />

            <xf:formrow>
                <xf:if is="$attachmentData">
                    <xf:macro template="helper_attach_upload" name="upload_block"
                        arg-attachmentData="{$attachmentData}"
                        arg-forceHash="{$draft.attachment_hash}" />
                </xf:if>
            </xf:formrow>
        </div>
    </div>
</div>

With only that above the message variable is coming through as a blank string when stepping through my code with a debugger, so I currently at a point to where I'm unable to test if the preview will actually work.

I do see that in every other instance that the preview bb code is used there is a creator / function to setup a thread/post/conversation. Are these required to get the XF:Editor plugin working so that it can actually grab the message?
 
I haven't been able to make much progress on this blocker due to a vacation and also just getting lost in the sauce of the preview bbcode.

I am of the assumption that to get the preview to work I would have to take the same steps as anywhere else that is using it and have a function setup an actual post (blog post in this case) but not go through the motions of actually creating and saving one and then use a service (editor / creator) to return a preview.

Now my question being where should I store this in my addon's file structure? Or would it just be smarter to use an existing one and only return what I need for a preview (blog post content and nothing else)?
 
Well I am a big ol' dumb. I figured out why I did not have a message coming through the editor with the code in the controller. I forgot to surround the entire thing with a form action..

Now that I have that figured out and working (woooo previews!) I can now get back to scratching my skull at how to get attachments to work. I was able to find another thread, https://xenforo.com/community/threads/using-attachements-in-an-add-on.46546/, which gave me a really good lead but boy is it still confusing at first.
 
Back
Top Bottom