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

FireEvents

edited February 2011 in Vanilla 2.0 - 2.8
Can someone post some sample code that explains how custom events are used? Not sure what it is but I am not getting it.
Tagged:

Comments

  • Options
    Figured it out.
  • Options
    @fiazk and can you tell us how it works then?

    There was an error rendering this rich post.

  • Options
    RaizeRaize vancouver ✭✭
    yes please share the wealth
  • Options
    edited February 2011
    OK, apologies, realised my response was a bit void of anything helpful. :)

    Basically, within your plugin you create functions that follow this format:

    MODELCONTROLLER_FIREVENT_handler($Sender)

    Then when any events are fired, your function is also run. e.g.

    To fire an event after a discussion is saved..

    1. Locate which model or controller in application/vanilla carries out the save. In this case its applications/vanilla/controller/class.postcontroller.php

    2. Then look to see if there if an event is being fired , (line 195 - $this->FireEvent('AfterDiscussionSave');)

    3. in your plugin create the following function:

    public function PostController_AfterDiscussionSave_Handler(&$Sender) {
    // do whatever you need to do after a discussion has been saved
    }
    So as you can see, the format is PostController as the event is in the PostController class, AfterDiscussion as this is the event you want to attach, and finish with Handler.

    I think that covers it all.
  • Options
    *Bookmarked*, thanx fiazk

    There was an error rendering this rich post.

  • Options
    Thanks for info, we need more of this documented properly.
  • Options
    Note that if you need an event firing in a particular model or controller, let the developers know and they are OK with adding them to future releases.
  • Options
    Btw, it could be good idea to make all content generation event based.
    Right now if I need to write differently categories list I need to copy whole php file and change necessary part. Instead if it was event sequence I could just replace one event handler.
    What do you think?
  • Options
    edited February 2011
    You would probably need to extend the class and override the method.
  • Options
    I mean WriteDiscussion function, for example.
    So it'll be only data related things and bunch of events.
    And event handlers will do all actual writing.
  • Options
    There are also magic events which I wish were more plentiful, the documentation for them is currently incorrect though...

    There was an error rendering this rich post.

  • Options
    @ddumont Can you explain how magic events differ? with an example?
  • Options
    ddumontddumont ✭✭
    edited February 2011
    @fiazk
    They are handled differently, you can check the plugin documentation to see how they work... however instead of <controller>_<EventName>_Handler
    They are <Controler>_<MethodName>_<Before|After|Override>
    As long as the magic method was delcared with an x in front (more info in the plugin docs)

    There was an error rendering this rich post.

  • Options
    While it is all good.
    I think that it could be good idea to have all code between Before and Efter like events to be always enclosed by if statement. So handlers could pass instruction to skip original code (not whole method - just this portion).
    I think it makes whole approach much more elegant, and you won't need to existing copy code to different view if all you need is change small part only (and this is not separate method).
  • Options

    I need a fireEvet ..

Sign In or Register to comment.