You are here

function notifications_message_part in Notifications 6

Same name and namespace in other branches
  1. 5 notifications.cron.inc \notifications_message_part()
  2. 6.2 notifications.cron.inc \notifications_message_part()

Get message part

It searches for optional message group keys for options defaulting to $type 1. $type-[$event->type]-[$event->action] 2. $type-[$event->type] 3. $type

Parameters

$type: Message type to send, either 'event' or 'digest'

$key: Id of message part, ie 'header'

$method: Method by which message will be sent. Normally 'mail'

$event: Event data

Return value

Part of the message.

6 calls to notifications_message_part()
NotificationsTemplatesTests::testNotificationsTemplates in tests/notifications_templates.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_digest_group in ./notifications.cron.inc
Get text parts for digests.
notifications_digest_line in ./notifications.cron.inc
Digest each line, with some caching for performance
notifications_process_digest_long in ./notifications.cron.inc
Digest multiple events in a single message, long format.
notifications_process_digest_short in ./notifications.cron.inc
Digest multiple events in a single message, short format.

... See full list

File

./notifications.cron.inc, line 456

Code

function notifications_message_part($type, $key, $method, $param = NULL) {

  // If event passed check for predefined text or get optional keys from event
  if ($type == 'event' && is_object($param)) {
    if (isset($param->text[$key])) {
      return $param->text[$key];
    }
    else {
      $options = array(
        $param->type,
        $param->action,
      );
    }
  }
  elseif ($method == 'test') {

    // Little trick for this to be testable
    return "{$type} {$key} [type-name] [title] [site-name]";
  }
  else {
    $options = is_array($param) ? $param : array();
  }
  $keyparts = array_merge(array(
    'notifications-' . $type,
  ), $options);

  // Output some debugging info in case we dont find a suitable message part
  $output = "[UNDEFINED type = {$type}, method = {$method}, key = " . implode('-', $keyparts) . ']';
  while ($keyparts) {
    $groupkey = implode('-', $keyparts);
    if ($text = messaging_message_part($groupkey, $key, $method)) {
      $output = $text == MESSAGING_EMPTY ? '' : $text;
      break;
    }

    // If no text trim out latest part of the key and retry
    array_pop($keyparts);
  }
  return $output;
}