/**
  * Get EntityValidators for on-save validation.
  *
  * @see getValidationErrorLocalizer()
  *
  * @param bool $forCreation Whether the entity is created (true) or updated (false).
  *
  * @return EntityValidator[]
  */
 public function getOnSaveValidators($forCreation)
 {
     if ($forCreation) {
         $validators = $this->constraintProvider->getCreationValidators($this->getEntityType());
     } else {
         $validators = $this->constraintProvider->getUpdateValidators($this->getEntityType());
     }
     return $validators;
 }
Ejemplo n.º 2
0
 /**
  * Throws an exception if it would not be possible to save the updated items
  * @throws ChangeOpException
  */
 private function applyConstraintChecks(Item $item, ItemId $fromId)
 {
     $constraintValidator = new CompositeEntityValidator($this->constraintProvider->getUpdateValidators($item->getType()));
     $result = $constraintValidator->validateEntity($item);
     $errors = $result->getErrors();
     $errors = $this->removeConflictsWithEntity($errors, $fromId);
     if (!empty($errors)) {
         $result = Result::newError($errors);
         throw new ChangeOpValidationException($result);
     }
 }