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

How to extend a control

edited November 2005 in Vanilla 1.0 Help
What I want to do is to surround the DiscussionGrid by a <div> element. Now I'm wondering what would be the best way to go. I came up with the extension below, the only thing that bugs me about that solution is having to call the constructor of DiscussionGrid() directly. I'd rather be able to somehow extend the discussiongrid, but I can't seem to get that to work... Here's my code that I have now: if(($Context->SelfUrl == 'index.php') && $Context->Session->User->RoleID) { $Context->ObjectFactory->SetReference("DiscussionGrid", "MyHackedGrid"); class MyHackedGrid extends Control { var $Context; var $DiscussionGrid; function MyHackedGrid(&$Context, $DiscussionManager, $CategoryID, $View) { $this->Context =& $Context; $this->DiscussionGrid = new DiscussionGrid($Context, $DiscussionManager, $CategoryID, $View); } function Render() { $this->Context->Writer->Write('<div id="DiscussionGrid" style="border: 1px solid red">'); $this->DiscussionGrid->Render(); $this->Context->Writer->Write('</div>'); } } }
«1

Comments

  • Options
    edited November 2005
    Was actually hoping that mark would give his input if this is the best way to do this :)....
  • Options
    Well I suppose he's busy working on the next rev of Vanilla. When that's released, it should be easy to edit the site theme and add in your extra div.
  • Options
    Yeah, I guess he's too busy also :) But putting my div in a theme won't do the trick... I'm creating an extension, so that should be theme independant. Ah, it works anyway .... I guess working more with vanilla will teach me if this was the correct path to follow :)
  • Options
    MarkMark Vanilla Staff
    What you've done is actually the correct way for Vanilla <= 0.9.2. In 0.9.3 you will still be able to do that, but you will also be able to achieve it in a few other ways. One way would be to create two new controls that you then place into the Page_Render event (it's the only render event in 0.9.3 - all other render events are gone) before and after the datagrid. Another method in 0.9.3 would be to write two functions and add them to the DataGrid's PreRender and PostRender delegates. This is definitely the most optimal way to perform a simple div enclosure through extensions. Of course I would still recommend (as ben did) just changing your templates for something as menial as adding a div.
  • Options
    Hmm, that's interesting. You build such a great framework that's excellent for extensions (way better then the 'mods' of other forums), but you recommend to change the templates... Wouldn't that leed to mods for the forum instead of extensions?
  • Options
    MarkMark Vanilla Staff
    Well, if you want to release an extension that other people can use, then of course you should do it through the delegates. But if you're just doing it for your own purposes to make your installation of your forum look a particular way - I don't see the point in making it an extension since it will be slower than if you had just changed the template.
  • Options
    Ah, ok. That's certainly true. It's my intention to release it as an extension, so I'll go for the delegates. Thanks for pointing things out.
  • Options
    Wow! There's gonna be a pre_render and post_render? oh goodie!!
  • Options
    MAn... I wish I could participate in discussions like this. Alas, I'm way to uneducated in this kind of junk. And so I post meaningless comments. Such as this one. BAH!
  • Options
    Someday I need to write a post_render extension to run HTML Tidy.
  • Options
    MarkMark Vanilla Staff
    The delegates are going to be a very big stepping stone for Vanilla - allowing us to do just about anything we want and add things anywhere we want - whether it be something rendered to the screen or altering a data saving procedure. I've tried to guess what delegates people might want and put some into the code, but I know that I will have to create a "delegate request" section in the upcoming bug tracking site so that we can continue to add useful delegates to the code.
  • Options

    Ok, on to the next problem I encountered duing my extension creation:

    What I want to do is the discussionmanager not to use 'static paging' but I want to be completely free to set the offset & count. Ie. I want to be able to get rows 13 to 99.
    Ofcourse I could inherit from the standard discussionmanager, but then: what if someone has the WhisperExtension turned on? ... what brings me to the generic problem: what if more then 1 extension wants to override the discussionmanager?

    Currently it will take the last SetReference (if I'm not mistaking).

    The only thing I can think of, is to wait for 0.9.3 and hope ;-) that there will be a delegate during the GetDiscussionList that allows me to alter the created query before it's fired.... or are there better alternatives?

  • Options
    It's really too bad that the dev community around vanilla isn't big enough to discuss stuff like this :(
  • Options
    lechlech Chicagoland
    heh, most of the dev community is still trying to wrap their heads around marks insane classes! I've also been extra lazy being occupied with other things :/
  • Options
    MarkMark Vanilla Staff
    If you're looking to change the number of items that appear in any dataset, that is a configurable amount in the appg/settings.php file (or through the "settings / application settings" form). Other than that, yeah - you'll have to either reference an entirely new class (which brings you to the aforementioned problem of conflicting extensions).
  • Options
    um. Arent eithers usually followed by or's?
  • Options
    MarkMark Vanilla Staff
    Apparently not in this case. *shoots self*
  • Options
    lechlech Chicagoland
    edited November 2005

    >shoot self in foot
    I don't see any self here.
    >shoot me in foot
    There is no you in the foot.
    >shoot foot
    I don't know which foot you're talking about.
    >shoot left foot
    You don't have the gun.
    >get gun
    You take the gun.
    You're lantern just went out.
    You are attacked by grues.

    * * * YOU HAVE DIED * * *
  • Options
    wtf?
  • Options
    oooeh oeeh! I have a question Mark!! In the current Vanilla, the extension are loaded / executed before the other controls! This means, if I want to change control behaviour, or output data from e.g. the discussions grid, I have to do scary things... A better way maybe events, like you said you will add in another post. This means, I can subscribe my extension to an event which executes before or after the body render. Or maybe events like, comment_added, or comment_deleted... W000t :)
This discussion has been closed.