You are here

function heartbeat_messages_export in Heartbeat 6.4

Same name and namespace in other branches
  1. 6.3 heartbeat.admin.inc \heartbeat_messages_export()

Function to export messages to use as default

1 string reference to 'heartbeat_messages_export'
heartbeat_menu in ./heartbeat.module
Implementation of hook_menu().

File

./heartbeat.admin.inc, line 1342
Admnistration tasks for heartbeat.

Code

function heartbeat_messages_export($form_state = array()) {
  $form = array();
  $messages = heartbeat_messages('all', TRUE, TRUE);
  if (count($messages) == 0) {
    return t('There are not heartbeat messages to export.');
  }
  if (!isset($form_state['export'])) {
    $form['messages'] = array(
      '#tree' => TRUE,
    );
    foreach ($messages as $message) {
      $form['messages']['m_' . $message->hid] = array(
        '#type' => 'checkbox',
        '#title' => !empty($message->description) ? $message->description : str_replace('_', '', $message->message_id),
        '#default_value' => 0,
        '#description' => $message->message,
      );
    }
    $form['button'] = array(
      '#type' => 'submit',
      '#weight' => 10,
      '#value' => t('Export'),
    );
  }
  else {

    //show a textarea containg the exported configs
    $form['result'] = array(
      '#type' => 'textarea',
      '#title' => 'Exported heartbeat messages',
      '#description' => 'Copy this data and paste them in <strong>hook_heartbeat_message_info</strong>.',
      '#rows' => 15,
      '#attributes' => array(
        'readonly' => 'readonly',
      ),
      '#default_value' => var_export(heartbeat_messages_export_messages($form_state['export']), 1),
    );
  }
  return $form;
}