XF 2.0 canCreateThread() method and returning of a custom error message

Scandal

Well-known member
Below is a sample of a class extension (XF\Entity\Forum).
Code:
class Forum extends XFCP_Forum
{
    public function canCreateThread(&$error = null)
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST')
        { 
            $error = \XF::phraseDeferred('sc_myphrase');
            return false;                     
        }
        $main_reply = parent::canCreateThread($error); 
        return $main_reply;
    } 
}

The issue: I need during a post of a thread, to return an error message (sc_phrase). I mean after click the "Post thread" button.
But the system is returning instead of the sc_phrase, a "No permission" xF2 message.
I need to return the correct message (sc_phrase phrase).

Can you see something wrong on the code?
I mean logical errors, no xF2 normalization issues (the code is a sample of the original).

It seems that the return false is working, but not the $error.
 
Are you trying to display your error message when the user clicks the "Post thread" button\link or when they actually submit the form?
The canCreateThread is called from many locations and some do not take the returned error massegae into account.
If only once they submit the form, then perhaps look into extending actionPostThread() and check for $this->isPost()
Just wanting to throw an error without explaining why makes it difficult to figure out what you are trying to achieve and thus what is the best way to go about it.
 
Top Bottom