how to get all the fields that have been modified on entity save (form submit)? I am trying to figure out an efficient way to get the fields names/values that have been updated. It's kind of similar to what the diff module does to calculate changed on a node but not as detailed. I just want to see what fields have been updated when a user saves an entity. For example a user may not change the title but could change the body. I would like to build an api function returns that. something like this pseudo code:

// possibly on presave or form submit. 
function my_module_entity_presave() {
    // Return only the fields values that are not similar to the original node: 
    $modified = $entity-&gt;getModifiedFields();
}


and the method could be something like this psudo code:

public function getModifiedFields() {
  $original = $this-&gt;originalFieldsValues();
  $new = $this-&gt;newFieldValues();
  // compare original with new
  // finally return only modified fields name values.
  $modified = ['title' =&gt; 'new value', 'body' =&gt; 'new value' ...];
  return $modified 
}
When you are in the presave hook, the updated $node object will have $node-&gt;original, which is the node before things were changed.

Nodes also have a $node-&gt;toArray(), method that will flatten the object into a multidimensional associative array.

So, this

array_keys(DiffArray::diffAssocRecursive($node-&gt;toArray(), $node-&gt;original-&gt;toArray())


should


Take the $node and $node-&gt;original and convert them into arrays.
Run the two arrays through one of the Drupal helper classes that will generate differences in multidimensional associative arrays.
Return the top level keys.  Because of the ways nodes are built, this will be all of the changed property and field names.