When working with entity forms I discovered this interesting piece detecting whether an entity is a newly saved one.

$result = $entity->save();

if ($result == SAVED_NEW) {
    // This is a newly saved one
else {
  // This is an updated one





Saved you some valuable time?


Donate and get more free time-saving code on this website in the future.