Hello,
In a custom Hook, how would one get the previous attribute value in afterSave and/or beforeSave hook?
Example:
Let's say in UI someone changes the entity field 'myattribute' from 4 to 5 and hits save.
What I would like to achieve,
Using beforeSave and/or afterSave I would like to know if 'myattribute' has changed, what was the previous value of it and what is the new value of it.
MyCustomHook
In a custom Hook, how would one get the previous attribute value in afterSave and/or beforeSave hook?
Example:
Let's say in UI someone changes the entity field 'myattribute' from 4 to 5 and hits save.
What I would like to achieve,
Using beforeSave and/or afterSave I would like to know if 'myattribute' has changed, what was the previous value of it and what is the new value of it.
MyCustomHook
PHP Code:
public function afterSave(Entity $entity, array $options): void
{
if( $entity->isAttributeChanged('myattribute') ) {
//get previous attribute ?
//$entity->getPreviousAttribute('myattribute);
}
}
Comment