The onFormatMessageVars handler is called on an array of $vars
containing all of the variables about to be substituted into a notification message or email in the LiveWhale “messages” module. The example module below is abstracted from a need to overwrite certain variables in the RSVP “Registration Received” email.
<?php
$_LW->REGISTERED_APPS['my_app']=[
'title'=>'My App',
'handlers'=>['onFormatMessageVars'],
];
class LiveWhaleApplicationMyApp {
public function onFormatMessageVars($vars) {
global $_LW;
// if this is a registration received message
if (!empty($vars['registrations_url'])) {
// do things..
// e.g., edit $vars['date_time'] or any other notification variable
}
return $vars;
}
}
?>
This example uses the event_id (extracted from the end of ical_url) to add the group title for an event to an RSVP notification or confirmation email.
public function onFormatMessageVars($vars) {
global $_LW;
// if this is a registration received message
if (!empty($vars['registrations_url'])) {
// get event ID by pulling everything after last / in ical_url
$event_id = substr($vars['ical_url'], strrpos($vars['ical_url'], '/') + 1);
// get event info corresponding to that ID
$event_info = $_LW->read('events',['id'=>$event_id,'response_fields'=>'group_title']);
// set group_title variable from the response
$vars['group_title'] = (!empty($event_info[0]['group_title']) ? $event_info[0]['group_title'] : '');
}
return $vars;
}