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

Overriding XenForo Base feature instead of extending it.

JamieSinn

Active member
#1
Extending a base feature is easy, and is shown here: https://xenforo.com/community/threads/how-to-add-more-actions-to-an-existing-controller.11202/

Now, how would I go about overriding an existing controller. Would I essentially do the same, but change the action to be the one I want to override? (Coming from a Java/C#/C++ background, and you'd simply override the method you want.)

eg. Copy pasting the actionUpdate from ControllerPublic/Report.php and putting it in my addon like the above link and making changes that I want?
 

Chris D

XenForo developer
Staff member
#2
Yes that is possible. Really not recommended though as it would break any other add-ons which extend the same action.

Depending on exactly what you want to achieve it may be possible to extend the action rather than overriding it.
 

JamieSinn

Active member
#3
I'm looking to force sending an alert when a moderator resolves a report. Regardless of what they click or enter, I really just want to override one line,

But to do that, I have to override the entire actionUpdate function.

Is there any better way of doing this?
 

Chris D

XenForo developer
Staff member
#4
Is there any better way of doing this?
Yes.

You could extend the following two functions:

XenForo_Model_Report -> sendAlertsOnReportResolution()
XenForo_Model_Report -> sendAlertsOnReportRejection()

Something like this:
PHP:
public function sendAlertsOnReportResolution(array $report, $comment = '')
{
    $comment .= ' Handled by ' . XenForo_Visitor::getInstance()->username;
    parent::sendAlertsOnReportResolution($report, $comment);
}
 

JamieSinn

Active member
#6
Now, this does about 50% of what I want, it sends the message appending when I have the "send alert" box checked. I've been looking if I can change it programmically, but it seems that it's part of a base xenforo class for the datawriter.
I'm trying to find a way to set the datawriter to send an alert.

XenForo_DataWriter_Report in _postSave, where it cchecks for OPTION_ALERT_REPORTERS, but I can't seem to find a way to update it without overriding XenForo_ControllerPublic_Report and it's actionUpdate function. Is there a way I can do this via an addon?

Thanks!
 
#7
XenForo_DataWriter_Report in _postSave, where it cchecks for OPTION_ALERT_REPORTERS, but I can't seem to find a way to update it without overriding XenForo_ControllerPublic_Report and it's actionUpdate function. Is there a way I can do this via an addon?
Yes, but you need to use the class proxy system. There are some tutorials on this already:
In the new class, do something like this:

PHP:
<?php

class MyAddon_DataWriter_Report extends XFCP_MyAddon_DataWriter_Report
{
    protected function _postSave()
    {
        // do something before the original code is executed

        parent::_postSave();

        // do something after the original code is executed
    }
}
 

JamieSinn

Active member
#8
Yes, but you need to use the class proxy system. There are some tutorials on this already:
In the new class, do something like this:

PHP:
<?php

class MyAddon_DataWriter_Report extends XFCP_MyAddon_DataWriter_Report
{
    protected function _postSave()
    {
        // do something before the original code is executed

        parent::_postSave();

        // do something after the original code is executed
    }
}
Ah, I wasn't sure to what extent I was able to extend the classes. Awesome! Thanks!