You are here

function workflow_state_add_form_validate in Workflow 5.2

Same name and namespace in other branches
  1. 5 workflow.module \workflow_state_add_form_validate()

File

./workflow.module, line 1184

Code

function workflow_state_add_form_validate($form_id, $form_values) {
  $state_name = $form_values['state'];
  $wf_states = array_flip(workflow_get_states($form_values['wid']));
  if (array_key_exists('sid', $form_values)) {

    // Validate changes to existing state:
    // Make sure a nonblank state name is provided
    if ($state_name == '') {
      form_set_error('state', t('Please provide a nonblank name for this state.'));
    }

    // Make sure changed state name is not a duplicate
    if (array_key_exists($state_name, $wf_states) && $form_values['sid'] != $wf_states[$state_name]) {
      form_set_error('state', t('A state with the name %state already exists in this workflow. ' . 'Please enter another name for this state.', array(
        '%state' => $state_name,
      )));
    }
  }
  else {

    // Validate new state:
    // Make sure a nonblank state name is provided
    if ($state_name == '') {
      form_set_error('state', t('Please provide a nonblank name for the new state.'));
    }

    // Make sure state name is not a duplicate
    if (array_key_exists($state_name, $wf_states)) {
      form_set_error('state', t('A state with the name %state already exists in this workflow. ' . 'Please enter another name for your new state.', array(
        '%state' => $state_name,
      )));
    }
  }
}