You are here

function workflow_admin_ui_edit_form_validate in Workflow 6

Same name and namespace in other branches
  1. 6.2 workflow_admin_ui/workflow_admin_ui.module \workflow_admin_ui_edit_form_validate()
  2. 7.2 workflow_admin_ui/workflow_admin_ui.page.workflow.inc \workflow_admin_ui_edit_form_validate()
  3. 7 workflow_admin_ui/workflow_admin_ui.pages.inc \workflow_admin_ui_edit_form_validate()

Validate the workflow editing form.

See also

workflow_edit_form()

File

workflow_admin_ui/workflow_admin_ui.module, line 409
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_edit_form_validate($form_id, $form_state) {
  $wid = $form_state['values']['wid'];

  // Make sure workflow name is not a duplicate.
  if (array_key_exists('wf_name', $form_state['values']) && $form_state['values']['wf_name'] != '') {
    $workflow_name = $form_state['values']['wf_name'];
    $workflows = array_flip(workflow_get_all());
    if (array_key_exists($workflow_name, $workflows) && $wid != $workflows[$workflow_name]) {
      form_set_error('wf_name', t('A workflow with the name %name already exists. Please enter another name for this workflow.', array(
        '%name' => $workflow_name,
      )));
    }
  }
  else {

    // No workflow name was provided.
    form_set_error('wf_name', t('Please provide a nonblank name for this workflow.'));
  }

  // Make sure 'author' is checked for (creation) -> [something].
  $creation_id = _workflow_creation_state($wid);
  if (isset($form_state['values']['transitions'][$creation_id]) && is_array($form_state['values']['transitions'][$creation_id])) {
    foreach ($form_state['values']['transitions'][$creation_id] as $to => $roles) {
      if ($roles['author']) {
        $author_has_permission = TRUE;
        break;
      }
    }
  }
  $state_count = db_result(db_query("SELECT COUNT(sid) FROM {workflow_states} WHERE wid = %d", $wid));
  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)',
    )));
  }
}