Problem/Motivation
API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
The 'create' in hook_entity_create() doesn't mean 'saved for the first time'.
The docs say:
> This hook runs after a new entity object has just been instantiated.
but I think this could be made even clearer.
Something like:
> The entity has not been saved; to act on an entity being saved for the first time use hook_entity_insert().
The docs should also say that it's possible the hook to be invoked for dummy entities. Field UI module for example creates a new entity to show the 'default value' form element for a field.
Steps to reproduce
N/A
Proposed resolution
State more explicitly that the entity has not been saved.
Remaining tasks
None
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
None
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | suggestion.png | 42.54 KB | dcam |
Issue fork drupal-3309169
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3309169-hookentitycreate-should-clearly
changes, plain diff MR !14771
Comments
Comment #4
acbramley commentedTriaged as part of BSI, part of me wants to make this a task as it's just documentation clarification but I can see some people viewing this as a bug.
Comment #8
priyankapatel commentedAdded clarification to the documentation for hook_entity_create() to distinguish it from hook_entity_insert().
Comment #9
dcam commentedI left comments on the MR. I'm confident in the need to change the term "saved" to "stored" for consistency with
hook_entity_insert(), so I'm setting the status to Needs Work.Comment #10
priyankapatel commented@dcam I have updated my PR accordingly. Please review
Comment #11
dcam commentedThis needs additional changes. There were two uses of the word "saved" in each new comment. Only one instance was changed per comment. Additionally, the line wrap length of the comments is shorter than the 80 per line that are allowed. While this isn't a huge problem, it is a little strange. It's preferred to fill the lines up to the maximum as much as possible. For these reasons I'm setting the status back to Needs Work.
I left replacement suggestions for these comments in the MR. You may apply them by using the buttons above the suggestion as shown in this image:

You're under no obligation to use anyone's suggestions, including mine. But I'll note that I solved both of the issues I mentioned in the suggestions I made.
Comment #12
priyankapatel commented@dcam I have applied your suggestions. Thanx!
Comment #13
acbramley commentedUpdated the IS with the standard template and marking RTBC.
Comment #14
catchComment #17
catchCommitted/pushed to main, 11.x and 11.3.x, thanks!
Comment #21
catch