You are here

function messaging_message_part in Messaging 6

Same name and namespace in other branches
  1. 5 messaging.module \messaging_message_part()
  2. 6.2 messaging.module \messaging_message_part()

Returns parts of messages, that may be formatted for each sending method

@ TODO Review logic, optimizations, text pre-fetching @ TODO Glue text in a method-dependent way

First checks for message, key, method Then checks for message, key for method 'default' Finally checks default values from modules and hook_messaging()

Parameters

$group: String, specified by the module where the message originates. ie 'subscriptions-event'.

$key: String, key for the desired message part.

$method: String the mailing method that should be used. OPTIONAL

$getdefault: Boolean, whether to use the default if a specific message isn't available for the used method. OPTIONAL, Defaults to true.

Return value

Assembled text of a message part.

1 call to messaging_message_part()
messaging_admin_message_form in ./messaging.admin.inc
Edit message formats

File

./messaging.module, line 532

Code

function messaging_message_part($group, $key, $method = 'default', $getdefault = TRUE) {
  static $cache;
  if (isset($cache[$group][$key][$method])) {
    $text_part = $cache[$group][$key][$method];
  }
  else {
    if ($method && ($text = db_result(db_query("SELECT message FROM {messaging_message_parts} WHERE type = '%s' AND msgkey = '%s' AND method = '%s'", $group, $key, $method)))) {
      $text_part = $text;
    }
    elseif ($method == 'default' && ($text = messaging_message_info($group, $key))) {

      // Retry with default but also set the cache for this method
      $text_part = $text;
    }
    elseif ($method != 'default' && $getdefault && ($text = messaging_message_part($group, $key, 'default'))) {
      $text_part = $text;
    }
    else {
      $text_part = FALSE;
    }

    // Convert array into plain text
    if ($text_part && is_array($text_part)) {
      $text_part = implode("\n", $text_part);
    }
    $cache[$group][$key][$method] = $text_part;
  }
  return $text_part ? $text_part : '';
}