Issue
I would like to cancel the operation if persist after-has test.and i dont know how i tried the redirection goal in vain.
/**
* @param mixed $object
*/
public function prePersist($object)
{
if (is_null($object->getFile())) {
}
}
any help ?
Solution
It's probably a bit late for you. Since I was looking for the same thing though, here's my solution.
It seems not to be possible to do any validation in Sonatas prePersist method.
For a simple NotNull validation like you are doing it I'd add a simple validation constraint to the entity or if the field is not mapped to the form element itself.
If you want to do some extra validation during Sonatas save process, override the validate
method. This one is called before the prePersis
/preUpdate
methods and it allows you to add validation messages.
use Sonata\CoreBundle\Validator\ErrorElement;
public function validate(ErrorElement $errorElement, $object)
{
$errorElement->with('file')->addViolation('Hey, this is a validation message');
}
Answered By - Samuel Wicky
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.