1. 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.

Discussion in 'XenForo Development Discussions' started by JamieSinn, Apr 24, 2016.

  1. JamieSinn

    JamieSinn Active Member

    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?
  2. Chris D

    Chris D XenForo Developer Staff Member

    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.
  3. JamieSinn

    JamieSinn Active Member

    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, [​IMG]
    But to do that, I have to override the entire actionUpdate function.

    Is there any better way of doing this?
  4. Chris D

    Chris D XenForo Developer Staff Member


    You could extend the following two functions:

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

    Something like this:
    public function sendAlertsOnReportResolution(array $report$comment '')
    $comment .= ' Handled by ' XenForo_Visitor::getInstance()->username;
    SneakyDave and JamieSinn like this.
  5. JamieSinn

    JamieSinn Active Member

    Ah! Perfect, thanks!
  6. JamieSinn

    JamieSinn Active Member

    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?

  7. MaGeFH

    MaGeFH Member

    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:


    class MyAddon_DataWriter_Report extends XFCP_MyAddon_DataWriter_Report
        protected function 
    // do something before the original code is executed


    // do something after the original code is executed
  8. JamieSinn

    JamieSinn Active Member

    Ah, I wasn't sure to what extent I was able to extend the classes. Awesome! Thanks!

Share This Page