how to call to other add-on's method from my add-on using $this ?

Earl

Well-known member
I'm trying to add a custom inline mod option

@Snog helped me with this code
https://xenforo.com/community/threa...core-methods-with-addons.119132/#post-1086469

Extend the library/XenForo/Model/Post.php class and use something like this to extend the function...
Code:
public function addInlineModOptionToPost(array &$post, array $thread, array $forum, array $nodePermissions = null, array $viewingUser = null)
{
      $parentResponse = parent::addInlineModOptionToPost($post, $thread, $forum, $nodePermissions, $viewingUser)
      $parentResponse['delete_rating'] = false;

      if ($this->canDeleteRating($post, $thread, $forum, $null, $nodePermissions, $viewingUser))
      {
         $parentResponse['delete_rating'] = true;
      }

      return $parentResponse;
}

but when the code gets executed, I get the error
( ! ) Fatal error: Call to undefined method MyAddon_Model_Post::canDeleteRating() in /var/www/html/library/MyAddon/Model/Post.php on line 15

yzZqozd.png


so the problem in this line:
Code:
if ($this->canDeleteRating($post, $thread, $forum, $null, $nodePermissions, $viewingUser))
and its looking for a method in my addon, which has defined in the original post ratings addon:
Code:
class Dark_PostRating_Model extends XenForo_Model
{
    public function canDeleteRating(array $post, array $thread, array $forum = array(), &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
    {
        $this->standardizeViewingUserReferenceForNode($thread['node_id'], $viewingUser, $nodePermissions);

        if (!$viewingUser['user_id'])
        {
            $errorPhraseKey = 'login_required';
            return false;
        }
        if ($post['message_state'] != 'visible')
        {
            return false;
        }
    
        return XenForo_Permission::hasContentPermission($nodePermissions, 'deleteRating');
    }
}



I need to run the check : "$this->canDeleteRating($post, $thread, $forum, $null, $nodePermissions, $viewingUser"
before I add the option.
Please help..
 
Last edited:
Make sure to set your Listener Execution order number above the one of the addon whose functions you need.
 
Make sure to set your Listener Execution order number above the one of the addon whose functions you need.
Did you mean this value?

qynY6FR.jpg

I changed it to "11"
The main add-on has '10', but It's still giving me the same error :unsure:

yzZqozd.png
 
Last edited:
@katsulynx
in main add-on
"class Dark_PostRating_Model extends XenForo_Model"
it's not using XFCP system to extend. is that the problem?
 
When a class extends a main XF class, in this case XenForo_Model, it is it's own class and you would extend it. If it's using XFCP, then you would normally extend the XF class and not the add-on's class. There may be exceptions to that.
 
Top Bottom