Signals: sending data between independent modules

When certain events occur in one of Zenario's modules - for example, a content item is published, a form is submitted - that module can broadcast a "signal" to let other modules know that the event occurred.

In this way, some module A can broadcast the signal, and some action can be taken by module B, without A needing to be dependent on B. This means you can have module B just installed on certain client sites where you need it.

Each signal that's sent has a name, and receiving modules "listen" for signals with a specific name. If the module then "hears" that name it will take the appropriate action and run some code as a result.

Signals may arise from an event on the visitor-facing site, in Organizer, or in other ways. For example, when a form is submitted there is an option to send a signal out to any modules that may be listening to action an event. You can also see the signal name for reference on this screen as well.

Signal form example

Creating a PHP method that listens for a signal

In order for a module listen for signals, you must first add an entry in your module's description.yaml for each signal that you wish to receive. Then you must create an appropriate method in your module to deal with the signal.

These methods need to be named after the signal that they are receiving and have a set form. For example the following function will be called when the signal eventMenuItemCreated is sent, indicating that a menu node has been created with a given menu node ID ($mID):

public static function eventMenuItemCreated($mID) {
    ...
    return true;
}

Similarly when a content item is published, a module including the following function will listen for the signal called eventContentPublished, with that signal containing the content item ID, Type and Version:

public static function eventContentPublished($cID, $cType, $cVersion) {
    ...
    return true;
}

A third example is when a user is deleted. A module containing user data may want to do its own updating (e.g. delete any data it was holding for the deleted user):

public static function eventUserDeleted($userId) {
    ...
    return true;
}

Reference for signals: