You are here

function _workflow_admin_ui_transition_grid_form in Workflow 7.2

Same name and namespace in other branches
  1. 7 workflow_admin_ui/workflow_admin_ui.pages.inc \_workflow_admin_ui_transition_grid_form()

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

Some special situations exist:

  • it is not allowed to go to the '(creation)' state.
  • all roles are permitted to use the 'stay on this state' transition. So, this is hidden from the user.

Parameters

Workflow $workflow: The Workflow object.

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

File

workflow_admin_ui/workflow_admin_ui.page.transitions.inc, line 55
Provides an Admin UI page for the Workflow Transitions.

Code

function _workflow_admin_ui_transition_grid_form($form, &$form_state, $workflow) {
  $form = array(
    '#tree' => TRUE,
  );
  $states = $workflow
    ->getStates($all = 'CREATION');
  if (!$states) {
    $form['error'] = array(
      '#type' => 'markup',
      '#value' => t('There are no states defined for this workflow.'),
    );
    return $form;
  }
  $roles = workflow_get_roles();
  foreach ($states as $state1) {
    $from = $state1->sid;
    foreach ($states as $state2) {

      // Don't allow transition TO '(creation)'.
      if (!$state2
        ->isCreationState()) {
        $to = $state2->sid;
        $stay_on_this_state = $to == $from;

        // Generate checkboxes for each transition.
        foreach ($roles as $rid => $role_name) {
          $checked = $stay_on_this_state;
          $config_transitions = $workflow
            ->getTransitionsBySidTargetSid($from, $to);
          if ($config_transition = reset($config_transitions)) {
            $checked |= $config_transition
              ->isAllowed(array(
              $rid,
            ));
          }
          $form[$from][$to][$rid] = array(
            '#type' => $stay_on_this_state ? 'hidden' : 'checkbox',
            '#title' => check_plain($role_name),
            '#default_value' => $checked,
            '#disabled' => $stay_on_this_state,
          );
        }
      }
    }
  }
  return $form;
}