if (!
$workflow->
getTypePlugin()->
hasState($entity->moderation_state->value
)) { // If the state we are transitioning to doesn't exist, we can't validate
// the transitions for this entity further.
$this->context->
addViolation($constraint->invalidStateMessage,
[ '%state' =>
$entity->moderation_state->value,
'%workflow' =>
$workflow->
label(),
]);
return;
} $new_state =
$workflow->
getTypePlugin()->
getState($entity->moderation_state->value
);
$original_state =
$this->moderationInformation->
getOriginalState($entity);
// 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