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.

Appending html to text formatter choices?

edited July 2006 in Vanilla 1.0 Help
I'm new to Vanilla and creating extensions for it.

I've made a text formatter, and I'd like to be able to provide a "quick help" link for it - perhaps a small popup or inline show/hide - after the formatter's name.

e.g: Format comments as [x] Text [ ] Formatter (help)

where "help" is my link.

I managed to find this discussion, which I think might be related, but I don't understand.

Thanks in advance. :)


  • Anyone?
  • ithcyithcy New
    edited July 2006
    i think that Mark will have to add a new delegate to the Framework.Class.Radio.php in order to have a link next to every radio button.

    if you want to have one link for "help on all formatting choices", you can do this:
    1. create your help file - let's call it "formatterHelp.html" and save it in the themes folder.
    2. in the themes folder, find post_formatter.php and copy it into the "vanilla" subfolder.
    3. edit the new copy. right after line 7 (which says ".$f->Get()") add your link.
    something like this: .'<a href="\'/forum/themes/formatterHelp.html\')">Help</a>'

    adjust as necessary of course.
    it would be better to do this with an extension, but that would require a new delegate as i said above.
    of course Mark's always been great about adding delegates, so that's not so unlikely to happen =)
  • Shoot. Yeah, this is for an extension I plan to share, so a manual theme modification would be a step backwards; I was hoping there was already a built-in way to do it, so I could provide it for users out-of-the-box. Thanks for your help though, at least I know how I can do this for myself. 'course, I hope Mark is listening too... :D
  • MarkMark Vanilla Staff
    Sure, I'll add that delegate.
  • Thanks Mark. :)
  • MarkMark Vanilla Staff
    Okay, so this required more work than I had anticipated.

    I altered the Radio class so that it has an optional $AppendItem third parameter in the AddOption method. Anything you put in there will be appended to each item after the label tag closes:

    // ItemAppend is a string that will be appended to each item after the label render. function AddOption($IdValue, $DisplayValue, $ItemAppend = '') { $this->aOptions[] = array('IdValue' => $IdValue, 'DisplayValue' => $DisplayValue, 'ItemAppend' => $ItemAppend); }

    Next I went into the DiscussionForm control and added the appropriate delegate and delegate parameters:

    function GetPostFormatting($SelectedFormatType) { $FormatCount = count($this->Context->StringManipulator->Formatters); $f = $this->Context->ObjectFactory->NewObject($this->Context, 'Radio'); $f->Name = 'FormatType'; $f->CssClass = 'FormatTypeRadio'; $f->SelectedID = $SelectedFormatType; $this->DelegateParameters['FormatRadio'] = &$f; $ItemAppend = ''; while (list($Name, $Object) = each($this->Context->StringManipulator->Formatters)) { $this->DelegateParameters['RadioItemName'] = &$Name; $this->DelegateParameters['RadioItemAppend'] = &$ItemAppend; $this->CallDelegate('PreFormatRadioItemAdd'); $f->AddOption($Name, $this->Context->GetDefinition($Name), $ItemAppend); $ItemAppend = ''; } $this->CallDelegate('PreFormatRadioRender'); $sReturn = ''; include(ThemeFilePath($this->Context->Configuration, 'post_formatter.php')); return $sReturn; }

    So, you'd attach to the PreFormatRadioItemAdd delegate and check the RadioItemName delegate parameter to see if it's the one you want to mess with. If it is, you can change the ItemAdd delegate parameter to be whatever you want. It's passed by reference, so it should come through and get added to the radio list just fine. It actually won't require much code on your part.

    This will allow you to make a unique help item for each one - or just add to the item you want individually.

    It also dawned on me that you could just alter the Definition of Html in the dictionary and add your anchor in there. But I don't know how that may adversely affect the clicking of the label.

    This has all been committed to svn and has NOT been tested.
  • Cool, thanks a lot. I'll try it out and report any problems that occur. :)
This discussion has been closed.