You are here

function heartbeat_messages_edit in Heartbeat 6.2

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

Function to maintain and administer heartbeat messages

Return value

settingsform

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

File

./heartbeat.admin.inc, line 114

Code

function heartbeat_messages_edit(&$form_state, $event = '', $edit = array()) {
  $form = array();
  $form[$event] = array(
    '#type' => 'fieldset',
    '#title' => t($event),
    '#collapsible' => true,
    '#collapsed' => FALSE,
    '#prefix' => '<p><strong>You can use the token replacements in your message.</strong></p>',
  );
  $result = db_query("SELECT * FROM {heartbeat_messages} WHERE event = '%s' LIMIT 1", $event);
  $message = db_fetch_object($result);
  $variables = heartbeat_decode_message_variables($message->variables);

  // the replacement of @ from # is only needed to view them like that.
  // The actual implementation needs the # for partial message translations
  $form[$event]['message'] = array(
    '#type' => 'textarea',
    '#title' => t($message->description),
    '#cols' => 10,
    '#rows' => 1,
    '#default_value' => empty($edit['message']) ? $message->message : $edit['message'],
    '#prefix' => '<p>' . t('<strong>Token replacements</strong>: <br />') . str_replace("#", "@", implode(', ', array_keys($variables))) . '.</p>',
  );
  $form[$event]['message_concat'] = array(
    '#type' => 'textarea',
    '#cols' => 10,
    '#rows' => 1,
    '#default_value' => empty($edit['message_concat']) ? $message->message_concat : $edit['message_concat'],
  );
  $form[$event]['karma_index'] = array(
    '#type' => 'textfield',
    '#title' => t('karma index'),
    '#required' => TRUE,
    '#default_value' => empty($edit['karma_index']) ? $message->karma_index : $edit['karma_index'],
  );
  $form[$event]['event'] = array(
    '#type' => 'hidden',
    '#default_value' => empty($edit['event']) ? $event : $edit['event'],
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (isset($edit['event'])) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
    $form['event'] = array(
      '#type' => 'value',
      '#value' => $event,
    );
  }
  return $form;
}