You are here

function Workflow::validate in Workflow 7

Validate the workflow. Generate a message if not correct. This function is used on the settings page of

Return value

boolean $isValid

File

includes/Entity/Workflow.php, line 208
Contains workflow\includes\Entity\Workflow.

Class

Workflow
@file Contains workflow\includes\Entity\Workflow.

Code

function validate() {
  $isValid = TRUE;

  // Don't allow workflows with no states. (There should always be a creation state.)
  $states = $this
    ->getStates();
  if (count($states) < 2) {

    // That's all, so let's remind them to create some states.
    $message = t('%workflow has no states defined, so it cannot be assigned to content yet.', array(
      '%workflow' => ucwords($this
        ->getName()),
    ));
    drupal_set_message($message, 'warning');

    // Skip allowing this workflow.
    $isValid = FALSE;
  }

  // Also check for transitions at least out of the creation state.
  // This always gets at least the "from" state.
  $transitions = workflow_allowable_transitions($this
    ->getCreationSid(), 'to');
  if (count($transitions) < 2) {

    // That's all, so let's remind them to create some transitions.
    $message = t('%workflow has no transitions defined, so it cannot be assigned to content yet.', array(
      '%workflow' => ucwords($this
        ->getName()),
    ));
    drupal_set_message($message, 'warning');

    // Skip allowing this workflow.
    $isValid = FALSE;
  }
  return $isValid;
}