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

CommentFileSizeAuthor
#11 suggestion.png42.54 KBdcam

Issue fork drupal-3309169

Command icon 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:

Comments

joachim created an issue. See original summary.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

acbramley’s picture

Issue tags: +Bug Smash Initiative

Triaged 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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

priyankapatel made their first commit to this issue’s fork.

priyankapatel’s picture

Status: Active » Needs review

Added clarification to the documentation for hook_entity_create() to distinguish it from hook_entity_insert().

dcam’s picture

Status: Needs review » Needs work

I 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.

priyankapatel’s picture

Status: Needs work » Needs review

@dcam I have updated my PR accordingly. Please review

dcam’s picture

Status: Needs review » Needs work
StatusFileSize
new42.54 KB

This 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:
A screenshot of the GitLab MR comments highlighting the "Apply suggestion" button
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.

priyankapatel’s picture

Status: Needs work » Needs review

@dcam I have applied your suggestions. Thanx!

acbramley’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Updated the IS with the standard template and marking RTBC.

catch’s picture

Title: hook_entity_create() should clearly state the entity is unsaved and mention the hook can be invoked for dummy entities » hook_entity_create() should clearly state the entity is not yet stored

  • catch committed 9f66234e on 11.3.x
    task: #3309169 hook_entity_create() should clearly state the entity is...

  • catch committed 6937c225 on 11.x
    task: #3309169 hook_entity_create() should clearly state the entity is...
catch’s picture

Version: main » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main, 11.x and 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed ee86116f on main
    task: #3309169 hook_entity_create() should clearly state the entity is...

catch’s picture

Version: main » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.