How know inside hook_entity_presave() if the entity is create or update please ? Thanks.
Note: I want use presave and not update and insert hook.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityLike this:
if ($node->isNew()) {
}
Note that this only works before saving, in insert/update, it will always return TRUE, because the node has already been saved and is no longer new.
In addition to the above answer, you also could check
if (!empty($node->nid)) {
}
An updated entity will always contain a copy of the original entity:
if (isset($entity->original)) {
}