Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Hijacking Vanilla classes via the ObjectFactory...

edited July 2008 in Vanilla 1.0 Help
So, I'm trying to decorate the Panel class to add some extra special functionality to it. Based on my close reading of the ObjectFactory documentation, it seems like the way to go is to extend Panel with my own class and then use the SetReference method to make my class the instantiated Panel class. Here's my test code in my extension's default.php file:

class CONPanel extends Panel { function CONPanel(&$Context) { // Silly PHP doesn't chain base class constructors. Panel::Panel($Context); echo '<h1 class="StartNew">Blargh!!</h1>'; } } // Replace the Panel class in the object factory with our own. $Context->ObjectFactory->SetReference("Panel", "CONPanel");

This, unfortunately, does nothing. I don't see Blargh output anywhere. I know that this file is being parsed because if I put random crap in it, I get PHP errors. I am a C++ ninja, not a PHP guru, so I don't know if the problem is my PHP or that this just isn't possible, though it seemed like this was exactly the kind of thing the ObjectFactory is for. Anyone got any ideas?


  • Options
    Ok, I'm pretty sure I figured this out, for the record. This *would* work, except that extension files are included after the Panel class has already been created in the init_vanilla.php file. Which is really too bad, because it would be great to be able to decorate core Vanilla classes.
  • Options
    edited July 2008
    For the record, you would actually use $this->Panel($Context); But you're also right: extensions are loaded after the core controls, so you are only able to override the other, non-core controls.

    You're on the right track though!
  • Options
    I hope it will changed in Vanilla 2; that extensions don't rely on global variables and that they they will be loaded first. But there is no way to do that in vanilla 1 without breaking most extensions.
  • Options
    Sorry if this is personel, but what do you want to do? Could you do it with a theme?
  • Options
    I was interested in changing the default name of the .php file that Panel includes for panel display. I have my own version that I would like to use, but as it is, I have to go manually edit whatever panel.php the current theme is using. If I switch themes, gotta go edit that one, too. It would be nice to just have a single point of maintenance.
This discussion has been closed.