You are here

function workflow_admin_ui_transitions_form_validate 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_transitions_form_validate()

Validate the workflow editing form.

See also

workflow_edit_form()

File

workflow_admin_ui/workflow_admin_ui.pages.inc, line 455
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_transitions_form_validate($form, $form_state) {
  $workflow = $form_state['values']['workflow'];
  $wid = $workflow->wid;

  // Make sure 'author' is checked for (creation) -> [something].
  $creation_state = $workflow
    ->getCreationState();
  $creation_sid = $creation_state->sid;
  if (isset($form_state['values']['transitions'][$creation_sid]) && is_array($form_state['values']['transitions'][$creation_sid])) {
    foreach ($form_state['values']['transitions'][$creation_sid] as $to => $roles) {
      if ($roles['author']) {
        $author_has_permission = TRUE;
        break;
      }
    }
  }
  $state_count = db_query('SELECT COUNT(sid) FROM {workflow_states} WHERE wid = :wid', array(
    ':wid' => $wid,
  ))
    ->fetchField();
  if (empty($author_has_permission) && $state_count > 1) {
    form_set_error('transitions', t('Please give the author permission to go from %creation to at least one state!', array(
      '%creation' => $creation_state
        ->label(),
    )));
  }
}