You are here

function notifications_scheduler_admin_send_form in Notifications 7

Preview form to send notifications

1 call to notifications_scheduler_admin_send_form()
notifications_scheduler_admin_form in notifications_scheduler/notifications_scheduler.admin.inc
Event configuration administration

File

notifications_scheduler/notifications_scheduler.admin.inc, line 49

Code

function notifications_scheduler_admin_send_form($form, &$form_state, $action) {
  drupal_set_title(t('Preview: @action', array(
    '@action' => $action['label'],
  )));
  $form['notification'] = array(
    '#type' => 'fieldset',
    '#title' => t('Scheduled notification'),
  );
  $form['notification']['action'] = array(
    '#type' => 'item',
    '#title' => t('Action'),
    '#markup' => $action['label'],
  );
  $event = notifications_scheduler_admin_action_build($action);
  $form['event'] = array(
    '#type' => 'value',
    '#value' => $event,
  );
  $sids = $event
    ->get_subscriptions();
  $form['sids'] = array(
    '#type' => 'value',
    '#value' => $sids,
  );
  $form['subscriptions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Subscriptions (@count)', array(
      '@count' => count($sids),
    )),
    '#collapsible' => count($sids) > 2,
    '#collapsed' => count($sids) > 10,
  );
  $form['subscriptions']['list']['#markup'] = theme('notifications_admin_subscription_list', array(
    'sids' => $sids,
  ));

  // Render some template parts
  $template = $event
    ->get_template();

  // Add current user so we can see some token replacement in action
  global $user;
  if (($method = messaging_method_default($user)) && ($destination = messaging_send_method($method)
    ->user_destination($user))) {
    $template
      ->set_destination($destination);
  }
  $template
    ->set_format(MESSAGING_FORMAT_HTML);
  $form['message'] = array(
    '#type' => 'fieldset',
    '#title' => t('Message preview (HTML)'),
    '#collapsible' => TRUE,
  );
  $form['message']['subject'] = array(
    '#title' => t('Subject'),
    '#type' => 'item',
    '#markup' => $template
      ->render('subject'),
  );

  // @todo Is this text safe for display without later filtering?
  $form['message']['body'] = array(
    '#type' => 'item',
    '#title' => t('Body'),
    '#markup' => $template
      ->render('body'),
  );
  $template
    ->set_format(MESSAGING_FORMAT_PLAIN);
  $form['plaintext'] = array(
    '#type' => 'fieldset',
    '#title' => t('Message preview (Plaintext)'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['plaintext']['subject'] = array(
    '#title' => t('Subject'),
    '#type' => 'item',
    '#markup' => '<pre>' . check_plain($template
      ->render('subject')) . '</pre>',
  );

  // @todo Is this text safe for display without later filtering?
  $form['plaintext']['body'] = array(
    '#type' => 'item',
    '#title' => t('Body'),
    '#markup' => '<pre>' . check_plain($template
      ->render('body')) . '</pre>',
  );
  if (count($sids)) {
    $form['send'] = array(
      '#type' => 'fieldset',
      '#title' => t('Send'),
    );
    $form['send']['button'] = array(
      '#type' => 'submit',
      '#value' => t('Send now'),
    );
  }

  // We need explicit submit callback as this form can be wrapped by others
  $form['#submit'][] = 'notifications_scheduler_admin_send_form_submit';
  return $form;
}