You are here

function workflow_extensions_workflow_form_validate in Workflow Extensions 7

Same name and namespace in other branches
  1. 6 workflow_extensions.module \workflow_extensions_workflow_form_validate()

Validate the workflow form, in particular the state transition comment and the scheduled state transition time (the date is a drop-down so requires no validation).

1 string reference to 'workflow_extensions_workflow_form_validate'
workflow_extensions_form_alter in ./workflow_extensions.module
Implements hook_form_alter().

File

./workflow_extensions.module, line 283
UI-related improvements to the Workflow module and tokens for Rules.

Code

function workflow_extensions_workflow_form_validate($form, &$form_state) {
  $nid = substr($form['#id'], strrpos($form['#id'], '-') + 1);
  $title = isset($form_state['values']['title']) ? $form_state['values']['title'] : (isset($form_state['values']['node']) ? $form_state['values']['node']->title : t('Content form'));
  if (!empty($form_state['values']['workflow_scheduled_hour'])) {
    if (!strtotime($form_state['values']['workflow_scheduled_hour'])) {
      form_set_error(is_numeric($nid) ? "workflow_scheduled_hour_{$nid}" : 'workflow_scheduled_hour', t('%title: scheduled time is not in the correct format.', array(
        '%title' => $title,
      )));
    }
  }
  if (!variable_get('workflow_extensions_allow_blank_comments', TRUE)) {
    if (!isset($form_state['values']['nid']) && !isset($form_state['values']['node'])) {

      // Bypass node creation
      return;
    }
    $comment = $form_state['values']['workflow_comment'];
    if (!trim($comment)) {
      form_set_error(is_numeric($nid) ? "workflow_comment_{$nid}" : 'workflow_comment', t('%title: please enter a non-blank comment for the workflow log.', array(
        '%title' => $title,
      )));
    }
  }
}