How do I update a field value in hook_entity_insert()? I want to update an field in hook_entity_insert(). The following code doesn't work. 

$entity-&gt;field_range-&gt;value = 'test';
$entity-&gt;save();


I also tried loading from node object, but still it doesn't work.

$node = \Drupal::entityManager()-&gt;getStorage('node')-&gt;load($entity-&gt;id());
$node-&gt;set('field_range', 'test');
$node-&gt;save();


After inserting the node only I will get the text "test" dynamically and it won't work in hook_entity_presave().

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.
From this solution we can able to do like below to update an field on hook_entity_insert

$entity-&gt;field_range-&gt;value = 'test';
drupal_register_shutdown_function('_cc_custom_post_insert',$entity);

function _cc_custom_post_insert($entity) {
    if($entity) {
        $entity-&gt;save();
    }
}