Check if the entity is new from the entity insert hook I have a custom content type, when I create a new content of this type via the admin ui I want be redirect to the edit page of the new node (not to the view page by default)

So, from an alter form hook, it's not possible because I don't know yet the node ID of the future node. From hook_entity_presave() it's the same: I don't know yet the node ID of the future node. From hook_entity_insert() hook, I have the node ID, but I don't know how can I check the entity is just created.

From hook_entity_insert(), is it possible to know if the entity is just created?
hook_entity_insert() is invoked only when an entity is created, not updated. That is evident from the method invoking it, EntityStorageBase::doPostSave().

  // Allow code to run after saving.
  $entity-&gt;postSave($this, $update);
  $this-&gt;invokeHook($update ? 'update' : 'insert', $entity);


hook_entity_update() is invoked for an entity being updated; otherwise hook_entity_insert() is invoked.

See also the description for the $update parameter passed to EntityStorageBase::doPostSave().


  bool $update: Specifies whether the entity is being updated or created.