You are here

function workflow_admin_ui_states_form_validate in Workflow 7.2

Validation handler for the state form.

File

workflow_admin_ui/workflow_admin_ui.page.states.inc, line 218
Provides an Admin UI page for the Workflow States.

Code

function workflow_admin_ui_states_form_validate($form, &$form_state) {

  // Because the form elements were keyed with the item ids from the database,
  // we can simply iterate through the submitted values.
  foreach ($form_state['values']['states'] as $sid => $item) {

    // Reload $state from db, in case the states were changed by anyone else. And it is just as fast.
    $state = workflow_state_load_single($sid);

    // Does user want to deactivate the state (reassign current nodes)?
    if ($sid > 0 && $item['status'] == 0 && $state
      ->isActive()) {
      $args = array(
        '%state' => $state
          ->getName(),
      );

      // check_plain() is run by t().
      // Does that state have nodes in it?
      if ($item['count'] > 0 && empty($item['reassign'])) {
        if ($form['#last_mohican']) {
          $message = 'Since you are deleting the last available workflow state
            in this workflow, all content items which are in that state will have their
            workflow state removed.';
          drupal_set_message(t($message, $args), 'warning');
        }
        else {
          $message = 'The %state state has content; you must reassign the content to another state.';
          form_set_error("states'][{$sid}]['reassign'", t($message, $args));
        }
      }
    }
  }
}