« All Handlers

onFormatMessageVars

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}