public static function Notifications_Message::build_simple_message in Notifications 7
Same name and namespace in other branches
- 6.4 includes/notifications_message.class.inc \Notifications_Message::build_simple_message()
Creates a single message for a single event
Parameters
$account: Destination user account
$event: Event object which caused this notification
$subscriptions: Array of subscription ids
$debug: Return template parts information with the message
Return value
Message object
2 calls to Notifications_Message::build_simple_message()
- notifications_content_test_template_submit in notifications_content/
notifications_content.admin.inc - Process template test
- Notifications_Message::build_simple in ./
notifications.message.inc - Digest multiple events in a single message, short format.
File
- ./
notifications.message.inc, line 118 - Drupal Notifications Framework - Default class file
Class
- Notifications_Message
- Wrapper for Notifications messages
Code
public static function build_simple_message($template, $event, $subscriptions, $module = 'notifications') {
$send_method = $template->method;
$destination = $template
->get_destination();
$account = $template
->get_user();
$language = $template
->get_language();
// Start the message by cloning the template
$message = clone $template;
$message
->add_event($event, $subscriptions);
// Create message. Do all this in one replacemente
$parts = array(
'subject' => $event
->message_part('subject', $send_method, $language, $module),
'header' => $event
->message_part('header', $send_method, $language, $module),
'event' => $event
->message_part('main', $send_method, $language, $module),
'footer' => $event
->message_part('footer', $send_method, $language, $module),
);
// We pass only the first subscription, which is at least something
// @ TODO Handle nicely the case where there are more than one subscription
$subscription = $subscriptions ? notifications_subscription_load(current($subscriptions)) : NULL;
$objects = array(
'destination' => $destination,
'user' => $account,
'event' => $event,
'subscription' => $subscription,
);
$objects = array_merge($objects, $event
->get_objects());
$text = messaging_template_text_replace($parts, $objects, $language);
// Get subject out of text and build the message array
$message->subject = $text['subject'];
unset($text['subject']);
$message->body = $text;
$message->text_parts = $parts;
return $message;
}