You are here

function messaging_template_get_defaults in Messaging 6.3

Get default text defined by modules

Parameters

$type: Template type

$language: Optional key to retrieve default for

$fallback: Whether to get all defaults recursing through fallbacks

4 calls to messaging_template_get_defaults()
messaging_template_edit_form in messaging_template/messaging_template.admin.inc
Edit message formats
Messaging_Template_Engine::get_default in messaging_template/messaging_template.inc
Get default provided by modules
messaging_template_get_template in messaging_template/messaging_template.module
Get text part with full data, handling fallbacks
Messaging_Template_Tests::testMessagingTemplateAPI in tests/messaging_template.test
Exercise basic API functions

File

messaging_template/messaging_template.module, line 267
Template system for Messaging Framework

Code

function messaging_template_get_defaults($name, $language = NULL, $fallback = FALSE) {
  static $cache;
  if (!isset($cache[$language->language][$name])) {
    $cache[$language->language][$name] = array();
    foreach (messaging_template_invoke_all('defaults', $name, $language) as $key => $value) {

      // Some value may be an array of text lines, implode before storing
      $cache[$language->language][$name][$key] = (object) array(
        'template' => is_array($value) ? implode("\n", $value) : $value,
        'options' => MESSAGING_TEMPLATE_DEFAULT,
        'type' => $name,
      );
    }
  }

  // If fallback, merge recursively all defaults for this template's fallbacks
  if ($fallback && ($name_fallback = messaging_template_fallback($name))) {
    return $cache[$language->language][$name] + messaging_template_get_defaults($name_fallback, $language, TRUE);
  }
  else {
    return $cache[$language->language][$name];
  }
}