isTransitionValid example

// If a new state is being set and there is an existing state, validate     // there is a valid transition between them.     if (!$original_state->canTransitionTo($new_state->id())) {
      $this->context->addViolation($constraint->message, [
        '%from' => $original_state->label(),
        '%to' => $new_state->label(),
      ]);
    }
    else {
      // If we're sure the transition exists, make sure the user has permission       // to use it.       if (!$this->stateTransitionValidation->isTransitionValid($workflow$original_state$new_state$this->currentUser, $entity)) {
        $this->context->addViolation($constraint->invalidTransitionAccess, [
          '%original_state' => $original_state->label(),
          '%new_state' => $new_state->label(),
        ]);
      }
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.