HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

Plugin Controller Method Override (Vanilla 2 Sub-Categories)

Hey,

I'm trying to write a plugin that will enable adding of sub-categories in vanilla 2.

I'm having problems overriding the default view for "Categories Add" method but anything I try does not work for me.

I Tried the following in my Plugin class:

public function CategoriesController_Add_Override(&$Sender){ $Sender->Render('views/categories/add.php'); }

But it does not work. I've also tried the following:

public function CategoriesController_Add_Render_Override(&$Sender){ $Sender->Render('views/categories/add.php'); }

and still no luck. Any help greatly appreciated.
Tagged:

Comments

  • I've tried few other things and the only way I was able to override Categories->Add Method was using "Declared Magic Event" and modifying the original Categories ->Add method by prefixing it with an 'x' but this is not the solution I'm looking for because plugin will not work when enabled on other vanilla 2 forums.
  • TimTim Operations Vanilla Staff
    From what I could tell from the controller's view, it looks like the adding functionality of categories is on the Settings Controller (since CategoriesController is a 'front end controller'). The method you'd be looking to intercept is SettingsController::AddCategory().

    So basically what you do is hook the Render() call for all methods on SettingsController, and then check Gdn::Dispatcher()->ControllerMethod() to detect when your particular method is being called and take action at that point.

    public function SettingsController_Render_Before($Sender) { if (Gdn::Dispatcher()->Application() == 'vanilla' && Gdn::Dispatcher()->ControllerMethod() == 'addcategory') $Sender->View = 'views/categories/add.php'; }
    Try that?

    Note: I just made this up, if it doesn't work we can try something else.

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • nice try but there seems to be an infinite loop there with magic events i think.

    [/web/forum/library/core/class.pluggable.php:192] Gdn_Dispatcher->xApplication(); [/web/forum/library/core/class.pluggable.php:192] Gdn_Pluggable->__call(); [/web/forum/library/core/class.pluggable.php:192] Gdn_Dispatcher->Application(); [/web/forum/library/core/class.pluggable.php:192] Gdn_Pluggable->__call(); ... and so on
  • I guess the only way to override views is just to put them into theme folder. For my example it would be sitting in:

    /themes/ThemeName/views/categories/add.php

    If anybody else got any ides let me know.

Sign In or Register to comment.