XF 2.0 BBCode that writes to a specific table

Case

Well-known member
I've followed the dev guide to create an addon that creates a new table with some columns for data.

I'd like for users to be able to write data to these columns via bbcode in posts - is this possible? Ideally I'd like to pass some other information from the post as well like user_id, post_id, thread_id to store in my new table.

So if I use the example below of a basic bbcode callback which takes a couple of options and prints them to the screen. Can I store the data from those options in my new table and grab some post data to store in the table as well?

Thanks in advance for any help.

PHP:
<?php
   
namespace TFC\BBCode\Test;
class BbcodeParser {
    public static function test($tagChildren, $tagOption, $tag, array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
    {
        $res = $renderer->renderSubTree($tagChildren, $options);
        $toptions = trim(strip_tags($tag['option']));
        $toptions = array_values(array_filter(explode(',', $toptions)));
        @list($data1, $data2) = $toptions;
        if ($tmp = trim($data1)) {
            $data1 = "$tmp";
        }
        if ($tmp = trim($data2)) {
            $data2 = "$tmp";
        }
        return "{$data1} {$data2}";
       
    }
}
 
It is possible to use the database object and run any kind of query on that. However, XF2 uses Entities, the entity manager and Services to actually create data.
Either way, I would suggest you not to use a BB code for that. The render method gets called on view, not only on post. Instead, use a code event listener on entity_post_save and check the $post.message for the structure you are looking for.
Anyways, what kind of data are we talking about? Usually you would want to use custom fields on threads, but they don't work on posts.
 
It is possible to use the database object and run any kind of query on that. However, XF2 uses Entities, the entity manager and Services to actually create data.
Either way, I would suggest you not to use a BB code for that. The render method gets called on view, not only on post. Instead, use a code event listener on entity_post_save and check the $post.message for the structure you are looking for.
Anyways, what kind of data are we talking about? Usually you would want to use custom fields on threads, but they don't work on posts.
OK, thanks.

I'm using bbcode because I'd like to style the appearance of the data the user enters in a post but then also be able to use that data separately elsewhere. It would be pretty basic stuff - probably just an id and a number within each occurrence of the bbcode.

I'm sure there would be better ways to capture the data but I like the ease & flexibility of bbcode.
 
If you go with the method I mentioned, once you have saved the entity, you could either create an extension of the post view action or use another code event listener (something with template_render or like that) to pass your data to the template. You won't get more flexibility than that.
 
Top Bottom