XF 2.1 Addon for new thread and something

Robert9

Well-known member
This is no request for coding! So dont move the thread, please.

I want to build something like this:
Add a new thread, see the form, add a checkbox.
When checked do something after saving the new thread like add data to different tables.

To code this for myself i need an existing addon as a base to watch and learn.
Finally i have to extend postsave/addthread (or something like this), take the incoming data like title and new thread_id and save it where and how i want.

So my question is, do we have any small and compact addon here that adds some data to a second table while adding a thread?
At the moment i have only the threadmarks to watch and learn and this is not the smallest addon; maybe there is a smaller one, please?
 
You might find the small portal addon described in the XF2 developer docs gives you a decent idea of how this all fits together: https://xenforo.com/xf2-docs/dev/lets-build-an-add-on/. The docs are far from comprehensive and the more complex abstractions will require sifting through the core code to get an understanding. That said, the concepts you're describing are among the ones addressed in the dev docs.

Some possible solutions:

Option 1: Create an addon that contains a code event listener of the entity_post_save type. This event fires after the _postSave() method of an entity runs. This listener will call a class and method of your choosing. Make sure to use an event hint so that your listener method only runs on the desired entity. (See ACP > Development > Code Event Listeners and the dev docs for details on the callback signature, how to hint, etc.)

Option 2: Create an addon that contains a class extension for the entity you want to change. Within the extension, define a _postSave() method that does the tasks you have in mind. You may need to call parent::_postSave() at the start of your method if the entity already has tasks it executes during post save. This is because the method defined in your extension will override the parent method.

It's hard to know which option would best suit your needs without knowing more about what you're trying to accomplish, but for what it's worth, Option 1 is the more appropriate choice in any scenario where you don't need to make further alterations beyond changing the post save behavior.
 
Back
Top Bottom