You are here

function workbench_email_transitions_form in Workbench Email 7

Administration form to create and delete email transitions.

Parameters

array $form: The form array

array $form_state: The form_state array

Return value

form A ready form array

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

File

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

Code

function workbench_email_transitions_form($form, &$form_state) {

  // List existing states.
  $types = drupal_map_assoc(workbench_moderation_moderate_node_types());
  $transitions = workbench_moderation_transitions();
  $roles = workbench_email_determine_valid_roles();
  if (!$types) {
    drupal_set_message(t('Moderation is not enabled for any content types. Visit
                         the <a href="@url"> content type administration
                         page</a> to enable moderation for one or more types.', array(
      '@url' => url('admin/structure/types'),
    )), 'warning');
    $form['#disabled'] = TRUE;
  }
  elseif (!$roles) {
    drupal_set_message(t('Moderation is not enabled for any roles. Visit the
                         <a href="@url"> user permissions page</a> to enable moderation
                         for one or more roles.', array(
      '@url' => url('admin/people/permissions', array(
        'fragment' => 'module-workbench_moderation',
      )),
    )), 'warning');
    $form['#disabled'] = TRUE;
  }
  else {
    $form['transitions'] = array(
      '#tree' => TRUE,
    );
  }
  foreach ($transitions as $transition) {
    $element = array();
    $element['transition'] = array(
      '#type' => 'value',
      '#value' => $transition,
    );
    $element['from_name'] = array(
      '#markup' => check_plain(workbench_moderation_state_label($transition->from_name)),
    );
    $element['to_name'] = array(
      '#markup' => check_plain(workbench_moderation_state_label($transition->to_name)),
    );
    foreach ($roles as $rid => $role) {
      $workbench_email = workbench_email_get($transition, $rid);
      $element[$role] = array(
        '#type' => 'checkbox',
        '#title' => check_plain(t(ucwords($role))),
        '#title_display' => 'invisible',
        '#default_value' => $workbench_email ? TRUE : FALSE,
      );
    }
    $form['transitions'][] = $element;
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}