You are here

function messaging_template_build in Messaging 6.4

Build message from template with token replacement

Parameters

$template: Template name to get text parts from

$send_method: Send method to build the template

$language: Language object

$objects: Objects for token replacement. Global tokens will be added always

$options: Aditional options for token replacement

$parts: Array of template parts. Default will be: subject, header, main, footer

Return value

Messaging_Message object

File

messaging_template/messaging_template.module, line 115
Drupal Messaging Framework - Messaging template

Code

function messaging_template_build($template, $send_method, $language, $objects = array(), $options = array(), $parts = array(
  'subject',
  'header',
  'main',
  'footer',
)) {
  $textparts = array();
  foreach ($parts as $key) {
    $textparts[$key] = messaging_template_text_part($template, $key, $send_method, $language);
  }

  // Run token replacement
  $text = messaging_template_text_replace($textparts, $objects, $language, $options);

  // Get subject out of text and build the message array
  if (isset($text['subject'])) {
    $subject = $text['subject'];
    unset($text['subject']);
  }
  else {
    $subject = '';
  }
  return new Messaging_Message(array(
    'subject' => $subject,
    'body' => $text,
    'language' => $language,
  ));
}