Override AbstractObject

I want to do some changes in thrown errors of save method in Pimcores core file Pimcore\Model\DataObject\AbstractObject

Is there any way to override this file in the AppBundle so that I can do my personal modification over pimcores save method for the object.

If overriding is possible then please provide steps to do the same within the bundle.

Hey,

There are multiple ways to do something on pimcore save. Best would be using the preUpdate events.

If you still want to go for the override, then would suggest instead of overriding - you create your own abstract layer for dataObjects in AppBundle.

  • Create an abstract class which extends the “Pimcore\Model\DataObject\Concrete”.
  • Your custom logic should call the instance of your custom abstract dataobject class.

I just want to change exception message format.

  1. Just throw your exception in specific condition
    throw new \Pimcore\Model\Element\ValidationException(“Validation failed:” . $validationMsg);
  2. Catch pimcore validation exception in your function by try catch then modify accordingly

Hello Vaishali,

I don’t have custom validation I just want to change default validation messages like on unique_contraint_violation I want to return field name on which this error received.

Hi @rajesh17692,

you can catch the default validation message on preUpdate and postUpdate event listener. after that, you will modify and throw the default validation message accordingly.