0

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?

2

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->postSave($this, $update);
  $this->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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.