function workflow_admin_ui_state_add_form_validate in Workflow 6.2
Same name and namespace in other branches
- 6 workflow_admin_ui/workflow_admin_ui.module \workflow_admin_ui_state_add_form_validate()
Validate the state addition form.
See also
workflow_state_add_form()
File
- workflow_admin_ui/
workflow_admin_ui.module, line 516 - 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_state_add_form_validate($form, &$form_state) {
$state_name = $form_state['values']['state'];
$wf_states = array_flip(workflow_get_states($form_state['values']['wid']));
if (array_key_exists('sid', $form_state['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_state['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,
)));
}
}
}