Is there any way to access original data in afterSave? I would like to log the changes on important data.
With $entity->isNew() I could check if it was an insert or an update, but how can I get what changed?
You can access the original values via Entity::getOriginal()
or Entity::extractOriginal()
. If you want to get all changed fields, combine the latter one with Entity::visibleProperties()
, something like:
debug($entity->extractOriginal($entity->visibleProperties()));
This should return the original values of all changed fields.
See also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With