You are here

public function Workflow::isValid in Workflow 8

Validate the workflow. Generate a message if not correct.

This function is used on the settings page of:

  • Workflow field: WorkflowItem->settingsForm()

Return value

bool $is_valid

Overrides WorkflowInterface::isValid

File

src/Entity/Workflow.php, line 185

Class

Workflow
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function isValid() {
  $is_valid = TRUE;

  // Don't allow Workflow without states.
  // There should always be a creation state.
  $states = $this
    ->getStates(FALSE);
  if (count($states) < 1) {

    // That's all, so let's remind them to create some states.
    $message = $this
      ->t('Workflow %workflow has no states defined, so it cannot be assigned to content yet.', [
      '%workflow' => $this
        ->label(),
    ]);
    $this
      ->messenger()
      ->addWarning($message);

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

  // Also check for transitions, at least out of the creation state.
  // Don't filter for roles.
  $transitions = $this
    ->getTransitionsByStateId($this
    ->getCreationSid(), '');
  if (count($transitions) < 1) {

    // That's all, so let's remind them to create some transitions.
    $message = $this
      ->t('Workflow %workflow has no transitions defined, so it cannot be assigned to content yet.', [
      '%workflow' => $this
        ->label(),
    ]);
    $this
      ->messenger()
      ->addWarning($message);

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