You are here

function state_flow_events_revision in State Machine 7

Same name and namespace in other branches
  1. 7.2 modules/state_flow/state_flow.pages.inc \state_flow_events_revision()

Form builder for the node revision workflow transition form.

1 string reference to 'state_flow_events_revision'
state_flow_menu in modules/state_flow/state_flow.module
Implements hook_menu().

File

modules/state_flow/state_flow.pages.inc, line 176

Code

function state_flow_events_revision($form, &$form_state, $node_revision, $new_event = NULL) {
  $form = array();
  $state_flow = state_flow_load_state_machine($node_revision);
  $all_events = $state_flow
    ->get_available_events();
  $events = array();
  foreach ($all_events as $event) {
    if (state_flow_access($node_revision, $event)) {
      $events[] = $event;
    }
  }
  if (empty($events)) {
    drupal_set_message(t('You cannot perform any workflow transitions on this revision.'), 'warning');
    drupal_goto('node/' . $node_revision->nid . '/workflow');
  }
  elseif (empty($new_event) || !in_array($new_event, $events)) {
    drupal_set_title(t('Transition revision @rev-vid to a new state', array(
      '@rev-vid' => $node_revision->vid,
    )));
    $form['event'] = array(
      '#type' => 'radios',
      '#title' => t('Choose the event to fire'),
      '#options' => drupal_map_assoc($events),
    );
  }
  else {
    drupal_set_title(t('Transition revision @rev-vid to %state', array(
      '@rev-vid' => $node_revision->vid,
      '%state' => $new_event,
    )), PASS_THROUGH);
    $form['event'] = array(
      '#type' => 'value',
      '#value' => $new_event,
    );
  }
  $form['event_comment'] = array(
    '#type' => 'textarea',
    '#title' => t('Log message for this state change'),
    '#default_value' => '',
    '#required' => TRUE,
  );
  $form['node_revision'] = array(
    '#type' => 'value',
    '#value' => $node_revision,
  );
  $form['state_flow'] = array(
    '#type' => 'value',
    '#value' => $state_flow,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update state'),
  );
  $form['cancel'] = array(
    '#markup' => l(t('Cancel'), 'node/' . $node_revision->nid . '/workflow'),
  );
  return $form;
}