Registering Callbacks
To register a callback for an event in Movable Type, you will need to make changes to your config.yaml
. You will need to have on hand two things:
- the name of the event you are listening for
- the package name and subroutine name to be invoked when the event occurs
For example, to register a callback for the MT::Entry pre_save event, use the following config.yaml
:
name: Example Plugin for Movable Type
id: Example
description: This plugin is an example plugin for Movable Type.
version: 1.0
callbacks:
MT::Entry::pre_save: $Example::Example::Plugin::entry_pre_save
You will then need to add an event handler or callback function to your Plugin.pm
file.
Tip: Registering Any-Class Object-level Callbacks
Developers can also register callbacks for all pre_save events by using a wildcard like so:
name: Example Plugin for Movable Type
id: Example
description: This plugin is an example plugin for Movable Type.
version: 1.0
callbacks:
'*::pre_save': $Example::Example::Plugin::entry_pre_save
“Any-class” callbacks are called after all class-specific callbacks.
carwellos on May 22, 2009, 6:18 a.m. Reply
Helpful, but the ‘Event Handlers’ information that follows this can be quite confusing to users - it goes right into presavefilter - close, but different than pre_save.
For clarity these two should be consistent, or make it very clear that the handler is not for this event.