You are here

function _workflow_admin_ui_update_configured_transitions in Workflow 7

Update the transitions for a workflow.

Parameters

array $transitions from values.: Transitions, for example: 18 => array( 20 => array( 'author' => 1, 1 => 0, 2 => 1, ) ) means the transition from state 18 to state 20 can be executed by the node author or a user in role 2. The $transitions array should contain ALL transitions for the workflow.

2 calls to _workflow_admin_ui_update_configured_transitions()
workflow_admin_ui_edit_form_submit in workflow_admin_ui/workflow_admin_ui.pages.inc
Submit handler for the workflow editing form.
workflow_admin_ui_transitions_form_submit in workflow_admin_ui/workflow_admin_ui.pages.inc
Submit handler for the workflow editing form.

File

workflow_admin_ui/workflow_admin_ui.module, line 338
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_update_configured_transitions($transitions = array()) {

  // Empty string is sometimes passed in instead of an array.
  if (!$transitions) {
    return;
  }
  foreach ($transitions as $from => $to_data) {
    foreach ($to_data as $to => $role_data) {
      foreach ($role_data as $role => $can_do) {
        if ($can_do) {
          $transition = array(
            'sid' => $from,
            'target_sid' => $to,
            'roles' => $role,
          );
          workflow_update_workflow_transitions($transition);
        }
        else {
          $roles = array();
          if ($transition = workflow_get_workflow_transitions_by_sid_target_sid($from, $to)) {
            $roles = explode(',', $transition->roles);
            $tid = $transition->tid;
            if (($i = array_search($role, $roles)) !== FALSE) {
              unset($roles[$i]);
              workflow_update_workflow_transitions_roles($tid, $roles);
            }
          }
        }
      }
    }
  }
  workflow_delete_workflow_transitions_by_roles('');
}