Entity save() in hook_ENTITY_TYPE_insert()

Created on 28 February 2024, 9 months ago
Updated 30 July 2024, 4 months ago

Problem/Motivation

The existing implementation of hook_ENTITY_TYPE_insert has two places where the entity is updated and saved. This is recursive and causes another round of calls to the presave and update hooks.

It is bad practice to save an entity while processing an insert or update hook. Changes to an entity should be done in a presave hook.

Proposed resolution

Add a new hook_ENTITY_TYPE_presave() and make the required updates there instead of in the insert hook.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇿New Zealand jlscott

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024