How to get nid while inserting new node drupal 8

by latikas   Last Updated January 04, 2018 13:07 PM

How to get nid when the entity is inserted. I need nid while inserting the entity and attach to the field value post data. I am trying to use hook_ENTITY_TYPE_presave() and hook_ENTITY_TYPE_insert() but unable to get nid. In hook_ENTITY_TYPE_presave(), I used following code

 if ($entity->isNew()) {
    print $entity->id();
 }
Tags : 8 entities hooks


Related Questions


Insert data into entity programmatically

Updated May 16, 2017 17:07 PM

How to create edit custom url for entity

Updated July 10, 2017 08:07 AM