XF 2.2 actionAddReply seems to return error prematurely?

kirsty

Member
I've got some code in my addon that extends Pub/Controller/Forum and intercepts the reply from actionPostThread to change a certain error reply (which I create in setupThreadCreate) into a view where the error can be corrected by the user. That all works fine.

I'm trying to do the same thing in the Pub/Controller/Thread to intercept the reply (created in setupThreadReply) in a similar way and I can't see why this isn't working. If I put the following in as my actionAddReply extension...

Code:
    public function actionAddReply(ParameterBag $params)
    {
        //return $this->error("add reply error 1");
        $view = parent::actionAddReply($params);
        return $this->error("add reply error 2");
    }

if I uncomment the first line then a reply will send the "add reply error 1", but if I use this code with the commented out first line I get the original error message that the reply triggered and not my "add reply error 2" one. I can't see why that happens? I only get the "add reply error 2" message if there wasn't any other error in the post.

Alternatively, is there a way I can send a view back directly from where I notice the problem with the post content in setupThreadCreate and setupThreadReply rather than creating an error that I then intercept later in the thread/post posting process?

Thanks for your help!
 
What is the original error message you are seeing? What error message are you trying to change, exactly?

An exception is likely being thrown, which can happen here because a) the request was not a POST request, b) the user has no permission to view the thread, or c) the user passed the rate limit (flooding). Otherwise a regular reply is returned as normal.
 
Thanks.

I'm adding my own error in setupThreadReply $thread->error('duplicate thing in post', 'loquax_error', $isDuplicate); and that's the error I'm seeing in the browser. If I don't add that error then I don't see an error from XF, and I just get a normal reply, so I don't think any other error reply should be triggered.

I do the same thing in setupThreadCreate when creating a new thread I then do this in actionPostThread

Code:
    public function actionPostThread(ParameterBag $params)
    {
        $view = parent::actionPostThread($params);
        $type = get_class($view);
        
        if ($type == "XF\Mvc\Reply\Error") {
            /** @var \XF\Mvc\Reply\Error $view */
            $errors = $view->getErrors();
            if (is_array($errors)) {
                if (!empty($errors['loquax_error'])) {
                       
                        return $this->view('Loquax\CompForum:Comp\DuplicateError', 'loquax_compforum_duplicate', $duplicate_info);
                }
            }
        }
        return $view;
    }

And that works fine for me, so I'm trying to do the some thing with replies.

But when I put the error into setupThreadReply and do similar to the above in actionAddReply I don't get back from the call to parent::actionAddReply

I guess I'll have to get this working on my local machine and see if I can get the debugger to tell me where it's going.
 
Getting my localhost instance running on my current code was (happily) less trouble than I thought it would be!

My problem seems to be that in Forum/actionPostThread my error gets caught and returned by the $creator->validate($errors) call, whereas in Thread/actionAddReply the error isn't being seen at the $replier->validate($errors) call and so the code is continuing to the $replier->save() call which then throws an exception.

Ah, I got it!

This is my problem (I think), in setupThreadReply I am using $thread->error(...) and I need to put the error on the post not the thread!
 
Top Bottom