XF 2.3 How to save additional data to a Post

delzhand

New member
I'm trying to add a checkbox to posts that allows users to toggle a change to the way the post is presented in a thread.

I've successfully added a column to the xf_post table. I have a listener that exposes the data to the post, and I'm able to both show a checkbox in the post_edit template populated with the right value and add a css class in post_macros where I need it. I manually flagged some posts in the database to test it out and these parts work great.

However, I'm struggling to figure out how to make the data persist when saved. Editing a post and checking an unchecked box (or vice versa) doesn't save the value to the db table.

The addon tutorial has a section about "Extending the forum save process", but there doesn't seem to be an equivalent to XF/Admin/Controller/Forum.php's saveTypeData in XF/Entity/Post.php, nor have I been able to figure out where else I might hook into this process.

I'm also not sure what the best way is to dump variables during post save. I haven't had any luck with \XF::dump because the post save process happens via JS.

Any guidance is appreciated.
 
Maybe you can help me figure out what I'm missing. I'm hoping all I've got wrong is template syntax. I'm trying to designate certain posts as official moderator statements, and so I added a "mod_decree" column to xf_post.

I've overridden post_edit with the following:

Find:
Code:
<xf:if is="$post.canSendModeratorActionAlert()"

Replace:
Code:
<xf:formrow name="mod_decree" rowtype="fullWidth noLabel">

    <xf:checkbox>

        <xf:option value="1" selected="$post.mod_decree"

            label="Make this post a Mod Decree"

            hint="If selected, report and react will be disabled and the post will gain a distinctive visual style." />

    </xf:checkbox>

</xf:formrow>

$0

When I edit a post that I've set the value for directly in the DB, the box is checked, so that's working at least. But in PostController::setupPostEdit() I've got these lines:

Code:
        $mod_decree = $this->plugin(EditorPlugin::class)->fromInput('mod_decree');
        \XF::dumpToFile($mod_decree);

That's modeled after
Code:
        $message = $this->plugin(EditorPlugin::class)->fromInput('message');

Which is my current best understanding of how data is parsed from the request.

The output file shows me that $mod_decree is an empty string. That's not entirely surprising, it appears that in order for that to work there would have to be mod_decree_html in the request object, which there isn't.

I feel like I'm close? I'm sure I can work out what needs to happen on the service side once I can clamp down on how exactly to pass data to the API.
 
Back
Top Bottom