Gallery3:Developer Handbook:Events - Gallery Codex
Personal tools

Gallery3:Developer Handbook:Events

From Gallery Codex

Events

Because Gallery 3 is modular in its nature, it’s important to let modules be loosely coupled. Tight bindings between modules (where one module directly calls into another one) reduces modularity and limits the possible ways that Gallery 3 can be deployed.

In Gallery 3, this loose coupling is accomplished by using an event system. Modules can publish arbitrary events whenever they choose, and any other module can listen for that event and take action on it. The gallery module has a set of events that it publishes, and many modules listen for and take action on these events. Event Reference

To implement an event listener for your module, you must create a special kind of helper called example_event. Any event that’s triggered will result in a static method call to this helper. For example, when an Item_Model is saved it will generate a “item_updated” event. This will attempt to call example_event::item_updated(). The item_updated() event takes two arguments, the original Item_Model and the newly updated Item_Model so the event handler can figure out what changed and take an appropriate action.

An attempt to detail all of the events currently defined in Gallery3 can be found on the Event Hooks page.

Notes about events:

  • Each event can specify the number and type of its arguments.
  • Module event handlers are called in the order that the modules were activated. You should not count on the module order
  • Kohana has its own events which modules can listen to, but in general this is discouraged. For most significant Kohana events there’s a matching Gallery event which your module can listen for instead.