You are here

function _workflow_admin_ui_transition_grid_form in Workflow 7

Same name and namespace in other branches
  1. 7.2 workflow_admin_ui/workflow_admin_ui.page.transitions.inc \_workflow_admin_ui_transition_grid_form()

Form builder. Build the grid of transitions for defining a workflow.

Parameters

int $wid: The workflow object.

1 call to _workflow_admin_ui_transition_grid_form()
workflow_admin_ui_transitions_form in workflow_admin_ui/workflow_admin_ui.pages.inc
Menu callback. Edit a workflow's transitions.

File

workflow_admin_ui/workflow_admin_ui.pages.inc, line 564
Provides administrative UI for workflow. Why it's own module? Lower code footprint and better performance. Additional credit 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_transition_grid_form($workflow) {
  $form = array(
    '#tree' => TRUE,
  );
  $roles = workflow_admin_ui_get_roles();
  $states = $workflow
    ->getStates();
  if (!$states) {
    $form['error'] = array(
      '#type' => 'markup',
      '#value' => t('There are no states defined for this workflow.'),
    );
    return $form;
  }
  foreach ($states as $state1) {
    $state_id = $state1->sid;
    $name = $state1
      ->label();
    foreach ($states as $state2) {
      $nested_state_id = $state2->sid;
      $nested_name = $state2
        ->label();
      if ($state2
        ->isCreationState()) {

        // Don't allow transition TO (creation).
        continue;
      }
      if ($nested_state_id != $state_id) {

        // Need to generate checkboxes for transition from $state to $nested_state.
        $from = $state_id;
        $to = $nested_state_id;
        foreach ($roles as $rid => $role_name) {
          $checked = FALSE;
          if ($transition = workflow_get_workflow_transitions_by_sid_target_sid($from, $to)) {
            $checked = workflow_transition_allowed($transition->tid, $rid);
          }
          $form[$from][$to][$rid] = array(
            '#type' => 'checkbox',
            '#title' => check_plain($role_name),
            '#default_value' => $checked,
          );
        }
      }
    }
  }
  return $form;
}