You are here

function workflow_edit_form_validate in Workflow 5

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_edit_form_validate()

File

./workflow.module, line 858

Code

function workflow_edit_form_validate($form_id, $form_values) {
  $wid = $form_values['wid'];
  if (array_key_exists('wf_name', $form_values) && $form_values['wf_name'] != '') {

    // Validate: Make sure workflow name is not a duplicate
    $workflow_name = $form_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 {
    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 (is_array($form_values['transitions'][$creation_id])) {
    foreach ($form_values['transitions'][$creation_id] as $to => $roles) {
      if ($roles['author']) {
        $author_has_permission = true;
        break;
      }
    }
  }
  if (!$author_has_permission) {
    form_set_error('transitions', t('Please give the author permission to go from %creation to at least one state!', array(
      '%creation' => '(creation)',
    )));
  }
}