• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XenForo_Phrase is being called twice in public function preSave()

AndyB

Well-known member
#1
I'm updating the code in my add-on called Smilie Count. When a new post is being created and there are too many smilies, I return this error. The problem is the error message is displayed twice.

PHP:
return $this->error(new XenForo_Phrase('please_reduce_the_number_of_smilies_maximum_allowed_is') . ' ' . $maxSmilieCount);
Here's the error message:

pic001.jpg
 

AndyB

Well-known member
#2
Here's the full code:

PHP:
<?php

class Andy_SmilieCount_DataWriter extends XFCP_Andy_SmilieCount_DataWriter
{
    public function preSave()
    {     
        // get smilies from xf_smilie table
        $smilies = $this->getModelFromCache('XenForo_Model_Smilie')->getAllSmilies();
             
        // get $maxSmilieCount from Admin CP -> Options -> Messages -> Maximum Smilies Per Post 
        $maxSmilieCount = XenForo_Application::get('options')->maxSmilieCount;     
     
        //########################################
        // count number of smilies in message
     
        $smilieCount = 0;
        foreach ($smilies as $smilie)
        {
            $smilieCount += substr_count($this->get('message'), $smilie['smilie_text']);
        }          
     
        // show error message if $smilie_count exceeds limit
        if ($smilieCount > $maxSmilieCount)
        {
            return $this->error(new XenForo_Phrase('please_reduce_the_number_of_smilies_maximum_allowed_is') . ' ' . $maxSmilieCount);
        } else {
            // run the original save() function
            return parent::preSave();
        }     
    }
}

?>
 
Last edited:

AndyB

Well-known member
#3
If I edit a post or create a new thread with too many smilies, the error message is displayed once as it should.
 

AndyB

Well-known member
#5
Thank you for the excellent suggestion, Amaury. I just tried disabling all the other add-ons and unfortunately the problem still occurs.
 

AndyB

Well-known member
#7
Hi Nobita.Kun,

When I try that I get the following error:

b>Fatal error</b>: Cannot override final method XenForo_DataWriter_DiscussionMessage::_preSave()
 

truonglv

Formerly Nobita.Kun
#8
Hi Nobita.Kun,

When I try that I get the following error:

b>Fatal error</b>: Cannot override final method XenForo_DataWriter_DiscussionMessage::_preSave()
What DataWriter you are extending?
If you're extends XenForo_DataWriter_Discussion_Thread or XenForo_DataWriter_DiscussionMessage_Post
So should be:
`_discussionPreSave` Or `_messagePreSave`
 

Amaury

Well-known member
#10