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.
FireEvents
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:
0
Comments
There was an error rendering this rich post.
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.
There was an error rendering this rich post.
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?
So it'll be only data related things and bunch of events.
And event handlers will do all actual writing.
There was an error rendering this rich post.
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.
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).
I need a fireEvet ..