1

I have a need to track changes to users in a separate database, apart from Drupal. When a user changes their email address or their password, I need to communicate that change with a shadow table in MSSQL.

I've created an event and listener. The event is triggered by hook_entity_update. That works fine, but I don't know what was changed in that request. Is there a way to pass the value that was changed to that event listener?

1 Answer 1

2

Per the hook_entity_update() documentation:

This hook runs once the entity storage has been updated. Note that hook implementations may not alter the stored entity data. Get the original entity object from $entity->original.

In your event listener, you can compare the email/password fields on $entity & $entity->original to check if they have changed.

1
  • Thanks, Shawn. I overlooked the $entity->original yesterday. That gets me what I need.
    – jscrilla
    Commented Aug 18, 2020 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.