You are here

function message_load in Message 6

Same name and namespace in other branches
  1. 7 message.module \message_load()

Message loader.

Parameters

$name: The name for this message object.

Return value

Returns a fully-loaded message definition.

5 calls to message_load()
message_action_load_message in includes/message.rules.inc
Action: Load a term.
message_action_load_message_form in includes/message.rules_forms.inc
Action: Load a message configuration form.
message_data_type_message::load in includes/message.rules.inc
Loads the data identified with an identifier as returned by get_identifier(). Just return the data or FALSE if loading the data failed.
message_get_string_i18n in ./message.module
Get the string of the message.
message_override_message_instance in ./message.module
Override the message, and if i18n module is enabled, register the string.
1 string reference to 'message_load'
message_schema in ./message.install
Implementation of hook_schema()

File

./message.module, line 288
API functions to manipulate messages.

Code

function message_load($name = NULL, $reset = FALSE) {
  ctools_include('export');
  if ($reset) {
    ctools_export_load_object_reset('message');
  }
  $messages = ctools_export_load_object('message', 'all');

  // We cache the i18n strings, so we don't re-create them every time. We don't
  // save the strings with variable_set() as it won't scale well with many
  // messages.
  if ($messages && module_exists('i18nstrings')) {

    // Check if translation was registered.
    $cache = cache_get('message_i18nstrings');
    $i18nstrings = array();
    $set = FALSE;
    foreach ($messages as $message) {
      if (empty($cache->data[$message->name])) {

        // Create string.
        i18nstrings_update("messages:message:{$message->name}:message", $message->message);
        $i18nstrings[$message->name] = TRUE;
        $set = TRUE;
      }
    }
    if ($set) {

      // Cache all the strings that were translated.
      cache_set('message_i18nstrings', $i18nstrings);
    }
  }
  if (isset($name)) {
    return isset($messages[$name]) ? $messages[$name] : FALSE;
  }
  return $messages;
}