XF 2.1 Extending thread create - showing validation errors.

arms

Well-known member
I'm trying to add an image when creating thread.

I've setup my plugin to use a service and works great on editing.
But I'm having problems getting my head around how to add to a new thread.

I've set it to run in finalizeThreadCreate(running here as need a thread_id), but if there is an exception (file too big) and show it, The thread is already saved and posted, therefore user would then fix the error and it would create a duplicate.

It works fine if there's no error but any advice appreciated.
 
It depends a lot on what exactly you're trying to do, but I'd maybe try to hook the life-cycle events normally (ie setup the image ahead of time and do validation by extending _validate()) and just fast-update the thread_id after saving.
 
Just to extend on what Jeremy P said, what does your service do? If the image is directly tied to the thread, then you'd probably be wanting to extend the \XF\Service\Thread\Creator service, and hooking into the \XF\Api\Controller\Threads::setupThreadCreate method to pass the image to the extended \XF\Service\Thread\Creator service.

You can then extend the \XF\Service\Thread\Creator services _validate and _save methods to do the actual validation and saving of the image.
 
Back
Top Bottom