Events and Packages

Permalink
Hey all!

Not sure how to do this, but i need it ;)

How can i install an event via a package, like in the site_events.php,

Thanks in Advanced ;)

Mnkras
 
synlag replied on at Permalink Best Answer Reply
synlag
taken from discussions pkg controller

// automatically run by the package. Let's setup some events
   public function on_start() {  
      Events::extendPageType('discussion', 'on_page_view');
      Events::extendPageType('discussion_post');
   }


greets
ron
Mnkras replied on at Permalink Reply
Mnkras
Cool thanks, thats what i thought just wantsn't sure, are you sure its the on_start function though?
synlag replied on at Permalink Reply
synlag
yup
jordanlev replied on at Permalink Reply
jordanlev
Note that you will also need to include this at the top of your package's on_start function:

if (!defined('ENABLE_APPLICATION_EVENTS')) {
   define('ENABLE_APPLICATION_EVENTS', true);
}
Mnkras replied on at Permalink Reply
Mnkras
you only need that in versions less than 5.4
jordanlev replied on at Permalink Reply
jordanlev
Sweet! I didn't know that (obviously).
Do you know how this works? Are events always on by default, or is there some check for if a package added an event or not?

Thanks!

-Jordan
Mnkras replied on at Permalink Reply
Mnkras
i think they are always on by default, its not like its resource consuming, it just fires a function each time Event::Fire is triggered,
andrew replied on at Permalink Reply
andrew
You only need to define ENABLE_APPLICATION_EVENTS to true in config/site.php if you plan on using config/site_events.php to store custom events. You don't need to enable it there if you want to use events defined in a package's on_start() function. Package developers should never need to include it or turn it on.
Mnkras replied on at Permalink Reply
Mnkras
oh, ok that makes sense
SkyBlueSofa replied on at Permalink Reply
SkyBlueSofa
Do I use this functionality if I want to add a 'on_page_save' event using a package?

I'd like to trigger the 'on_page_save' event when a user saves Page Defaults of any page type (Dashboard > Pages & Themes > Page Types > Defaults).
Mnkras replied on at Permalink Reply
Mnkras
yes, if you look in the Howto's section I just wrote up how to add your own.
SkyBlueSofa replied on at Permalink Reply
SkyBlueSofa
I'm looking to create an Add-On that will extend an dashboard page. Would this (or similar code) work to extend a core dashboard page? Or are the events only fired for front-end pages?
Mnkras replied on at Permalink Reply
Mnkras
yes, its used throughout c5