throw DataAbstractionLayerException::
invalidSerializerField(StateMachineStateField::
class,
$field);
} // Always allow any status when creating a new entity. A state transition from one state into another makes no
// sense in that case.
if (!
$existence->
exists()) { return parent::
encode($field,
$existence,
$data,
$parameters);
} // Allow the change of the stateMachineState if the scope is one of the allowed ones.
$scope =
$parameters->
getContext()->
getContext()->
getScope();
if (\
in_array($scope,
$field->
getAllowedWriteScopes(), true
)) { return parent::
encode($field,
$existence,
$data,
$parameters);
} // In every other case force the user to use a state-transition
$messageTemplate = 'Changing the state-machine-state of this entity is not allowed for scope {{ scope }}. '
. 'Either change the state-machine-state via a state-transition or use a different scope.';
$messageParameters =
[ '{{ scope }}' =>
$scope,
];
throw new WriteConstraintViolationException(new ConstraintViolationList([