public function OrderVersionConstraintValidator::validate in Commerce Core 8.2
File
- modules/
order/ src/ Plugin/ Validation/ Constraint/ OrderVersionConstraintValidator.php, line 16
Class
- OrderVersionConstraintValidator
- Validates the OrderVersion constraint.
Namespace
Drupal\commerce_order\Plugin\Validation\ConstraintCode
public function validate($entity, Constraint $constraint) {
if (isset($entity) && !$entity
->isNew()) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $saved_entity */
$saved_entity = \Drupal::entityTypeManager()
->getStorage($entity
->getEntityTypeId())
->loadUnchanged($entity
->id());
// A change to the order version must add a violation.
if ($saved_entity && $saved_entity
->getVersion() > $entity
->getVersion()) {
$this->context
->addViolation($constraint->message);
}
}
}