You are here

function workbench_email_form in Workbench Email 7

Same name and namespace in other branches
  1. 7.3 workbench_email.admin.inc \workbench_email_form()

Form for administering the email content.

Administrators can use this form to add, update, delete emails.

Parameters

array $form: The form array

array $form_state: The form_state array

Return value

form Returns the form array

1 string reference to 'workbench_email_form'
workbench_email_menu in ./workbench_email.module
Implements hook_menu().

File

./workbench_email.admin.inc, line 21
Administrative forms for Workbench Email Module.

Code

function workbench_email_form($form, &$form_state) {
  $workbench_emails = workbench_email_get();
  $state_labels = workbench_moderation_state_labels();
  foreach ($workbench_emails as $transition_label => $email_transition_set) {
    $state_label = $email_transition_set;
    $transition = array_shift($state_label);
    $transition_title = t(ucwords($state_labels[$transition->from_name] . ' To ' . $state_labels[$transition->to_name]));
    $form[$transition_label] = array(
      '#type' => 'fieldset',
      '#title' => check_plain($transition_title),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    foreach ($email_transition_set as $rid => $email_transition) {
      $subject = $email_transition->subject;
      $message = $email_transition->message;
      $role = user_role_load($rid);
      $params['rid'] = $rid;
      $params['role'] = $role->name;
      $params['from_state'] = $email_transition->from_name;
      $params['to_state'] = $email_transition->to_name;
      $form[$transition_label][$rid] = array(
        '#type' => 'fieldset',
        '#title' => check_plain(t("Email @role_name", array(
          '@role_name' => ucwords($role->name),
        ))),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form[$transition_label][$rid]['subject'] = array(
        '#type' => 'textfield',
        '#default_value' => $subject,
        '#title' => t('Subject'),
        '#maxlength' => 255,
      );
      $form[$transition_label][$rid]['message'] = array(
        '#type' => 'textarea',
        '#default_value' => $message,
        '#title' => t('Message'),
        '#size' => 30,
      );
    }
  }
  if ($workbench_emails) {
    $form['#tree'] = TRUE;
    $form['token_set'] = array(
      '#type' => 'fieldset',
      '#title' => t('Available Tokens'),
      '#collapsible' => TRUE,
    );
    $form['token_set']['tokens'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'node',
        'user',
      ),
      '#click_insert' => TRUE,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save Configuration'),
    );
  }
  else {
    drupal_set_message(t('No email transitions have been defined yet. Visit the
                         <a href="@url"> email transition configuration page</a>', array(
      '@url' => url('admin/config/workbench/moderation/email-transitions'),
    )), 'warning');
    $form['#disabled'] = TRUE;
  }
  return $form;
}