You are here

function workflow_admin_ui_state_delete_form in Workflow 6

Same name and namespace in other branches
  1. 6.2 workflow_admin_ui/workflow_admin_ui.module \workflow_admin_ui_state_delete_form()

Form builder. Create form for confirmation of deleting a workflow state.

Parameters

$wid: integer The ID of the workflow.

$sid: The ID of the workflow state.

Return value

HTML form.

1 string reference to 'workflow_admin_ui_state_delete_form'
workflow_admin_ui_menu in workflow_admin_ui/workflow_admin_ui.module
Implementation of hook_menu().

File

workflow_admin_ui/workflow_admin_ui.module, line 685
Provides administrative UI for workflow. Why it's own module? Lower code footprint and better performance. Additional creadit to gcassie ( http://drupal.org/user/80260 ) for the initial push to split UI out of core workflow. We're moving…

Code

function workflow_admin_ui_state_delete_form($form_state, $wid, $sid) {
  $states = workflow_get_states($wid);
  $state_name = $states[$sid];

  // Will any nodes have no state if this state is deleted?
  if ($count = db_result(db_query("SELECT COUNT(nid) FROM {workflow_node} WHERE sid = %d", $sid))) {

    // Cannot assign a node to (creation) because that implies
    // that the node does not exist.
    $key = array_search(t('(creation)'), $states);
    unset($states[$key]);

    // Don't include the state to be deleted in our list of possible
    // states that can be assigned.
    unset($states[$sid]);
    if ($states) {
      $form['new_sid'] = array(
        '#type' => 'select',
        '#title' => t('State to be assigned to orphaned nodes'),
        '#description' => format_plural($count, 'Since you are deleting a workflow state, a node which is in that state will be orphaned, and must be reassigned to a new state. Please choose the new state.', 'Since you are deleting a workflow state, @count nodes which are in that state will be orphaned, and must be reassigned to a new state. Please choose the new state.'),
        '#options' => $states,
      );
    }
    else {
      $form['warning'] = array(
        '#value' => format_plural($count, 'Since you are deleting the last workflow state in this workflow, the one remaining node which is in that state will have its workflow state removed. ', 'Since you are deleting the last workflow state in this workflow, @count nodes which are in that state will have their workflow state removed. '),
      );
    }
  }
  $form['wid'] = array(
    '#type' => 'value',
    '#value' => $wid,
  );
  $form['sid'] = array(
    '#type' => 'value',
    '#value' => $sid,
  );
  return confirm_form($form, t('Are you sure you want to delete %title (and all its transitions)?', array(
    '%title' => $state_name,
  )), !empty($_GET['destination']) ? $_GET['destination'] : 'admin/build/workflow', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
}