You are here

function heartbeat_features_export_render in Heartbeat 6.4

Implementation of hook_features_export_render().

File

./heartbeat.features.inc, line 58
Features support.

Code

function heartbeat_features_export_render($module = 'foo', $data) {
  $code = array();
  $info = array();

  // Begin code
  $code[] = '  $messages = array();' . "\n";

  // Gather all messages
  $messages = heartbeat_messages('all', TRUE, FALSE);
  foreach ($messages as $message) {
    $message = (object) $message;

    // Skip the message if it's not within the templates
    // registered by features.
    if (!in_array($message->message_id, $data)) {
      continue;

      // Leave if not selected
    }

    // Label the current message
    $code[] = '  // Exported heartbeat message: ' . $message->message_id;

    // Build message object
    $concat_args = heartbeat_decode_message_variables($message->concat_args);
    $variables = heartbeat_decode_message_variables($message->variables);
    $attachments = unserialize($message->attachments);
    $message = array(
      'message' => $message->message,
      'message_concat' => $message->message_concat,
      'message_id' => $message->message_id,
      'concat_args' => $concat_args,
      'description' => $message->description,
      'perms' => $message->perms,
      'custom' => HEARTBEAT_MESSAGE_DEFAULT,
      'variables' => $variables,
      'attachments' => $attachments,
    );

    // Add to code
    $code[] = '  $messages[\'' . $message['message_id'] . '\'] = ' . str_replace("\n", "\n  ", var_export($message, 1)) . ";\n";
  }

  // End code
  $code[] = "\n" . '  return $messages;';

  // Put code into a string
  $code = implode($code, "\n");
  return array(
    'heartbeat_message_info' => $code,
  );
}