Skip to main content

Creating an event listener

Events and event listeners allow custom logic to be run at the point an action is carried out within Jadu Central, such as a content item being saved or deleted.

A list of events present in the software is documented in this manual.

Throwing events

Events can be thrown in your custom developments by calling the fire method of the events container.

$object = new My\Event\Object();
Jadu_Service_Container::getInstance()->getEventContainer()->fire('my.event', $object);

fire takes two parameters, the name of the event to fire, and an object containing any values that should be passed to the event listener.

Listening to events

First create a class within jadu/custom that implements the JaduFramework\Event\Interfaces\InterfaceEvent.

use JaduFramework\Event\Interfaces\InterfaceEvent;
use JaduFramework\Event\Interfaces\InterfaceObject;

class Jadu_Custom_MyCustomEvent implements InterfaceEvent
{
public function run(InterfaceObject $object)
{
// add logic
}

public function name()
{
// return the name of the event which you are going to listen for
// example documentpage.save
}
}

The run method contains your logic. The method takes one parameter which is an InterfaceObject that is populated with data that is relevant to that event that is being listened out for.

For example, the documentpage.save event will return a Jadu_Document_Event_Object that is populated with a DocumentPage instance. You now have enough information to act upon this change.

The last step required is to register your new listener so that Jadu Central knows how to handle your custom Event.

  • Register your event within config/events.xml

This requires you to add the name of your class and the the event you are listening for:

<item key="documentpage.save">Jadu_Custom_MyCustomEvent</item>