You are here

function workflow_admin_ui_overview_form_validate in Workflow 7

Validation handler for the state form.

File

workflow_admin_ui/workflow_admin_ui.pages.inc, line 807
Provides administrative UI for workflow. Why it's own module? Lower code footprint and better performance. Additional credit 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_overview_form_validate($form, &$form_state) {

  // Get the workflow id.
  $workflow = $form_state['values']['workflow'];
  $wid = $workflow->wid;

  // 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 = WorkflowState::load($sid);

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

      // 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));
        }
      }
      if (module_exists('workflowfield')) {

        // @todo: Reassign states for Workflow Field.
        $message = 'Deactivating state %state for does not reassign Fields of type Workflow with this status.';
        drupal_set_message(t($message, $args), 'warning');
      }
    }
  }
}