Altering comment data on publishing I have a boolean field ( field_rejected ) in my custom comment implementation ,I need to set this field to false if this comment is published

I tried hook_comment_update and hook_comment_insert, This didn't work as it says in the documentation :


  "Note that hook implementations may not alter the stored entity data."


Then I tried doing this using hook_entity_presave but this also didn't work as it results in an infinite loading or error code 500.

This is the code I used:

function custom_comments_notification_comment_presave($comment) {
  if ($comment-&gt;isPublished() &amp;&amp; !$comment-&gt;original-&gt;isPublished()) {
    $comment-&gt;set('field_rejected', 0, $notify = true);
    $comment-&gt;save();
  }
}


Note that this is implemented in custom module's .module file.

How can I solve this? How can change the boolean 'field_rejected' after publishing a comment?
Remove that $comment->save(); Because you are already in the save process and you will trigger it over and over again with this.