Follow-up to #2490966: [Meta] Replace deprecated usage of entity_create with a direct call to the entity type class

Problem/Motivation

According to #2346261: Deprecate entity_create() in favor of a <EntityType>::create($values) or \Drupal::entityManager()->getStorage($entity_type)->create($values), entity_create() function is going to be deprecated so we shouldn't use it anymore. When the entity type is known we should directly call <EntityType>::create(). What to do when the entity type is not known or is variable is upon discussions.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task
Issue priority Normal because it's just about code cleanup and good practices
Prioritized changes The main goal of this issue is DX, performance and removing code already deprecated for 8.0.0. (Direct calls to EntityType::create are better than generic calls to entity_create for readability)
Disruption This change is not disruptive at all as it only replaces deprecated functions call by their exact equivalent.

Proposed resolution

Replace the deprecated call to entity_create() by a proper call to <EntityType>::create().

Before:

entity_create('field_config', $field_values)->save();

After:

use Drupal\field\Entity\FieldConfig;
FieldConfig::create($field_values)->save();

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions Done
Manually test the patch Novice Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions

User interface changes

None.

API changes

None.

Comments

Mac_Weber created an issue. See original summary.

mac_weber’s picture

StatusFileSize
new16.02 KB

Status: Needs review » Needs work

The last submitted patch, 2: node_type-2641604-2.patch, failed testing.

mac_weber’s picture

Status: Needs work » Needs review
StatusFileSize
new15.48 KB

Fixed class name

mac_weber’s picture

mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs reroll.

heykarthikwithu’s picture

Assigned: Unassigned » heykarthikwithu
heykarthikwithu’s picture

Assigned: heykarthikwithu » Unassigned
Status: Needs work » Needs review
StatusFileSize
new14.22 KB
heykarthikwithu’s picture

Issue tags: +@deprecated, +deprecated
dimaro’s picture

The latest patch doesn't apply for me.
Retest patch.

Status: Needs review » Needs work

The last submitted patch, 8: 2641604-8.patch, failed testing.

lluvigne’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new14.22 KB

Rerolled #8. Hope it works.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect for me.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs re-roll

Needs a re-roll.

lluvigne’s picture

Assigned: Unassigned » lluvigne
lluvigne’s picture

Assigned: lluvigne » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs re-roll
StatusFileSize
new14.29 KB

Rerolled #12.

mile23’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies, deals with all occurrences of entity_create('node_type')

  • catch committed a55d465 on 8.1.x
    Issue #2641604 by Mac_Weber, lluvigne, heykarthikwithu: Replace...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x, thanks!

Status: Fixed » Closed (fixed)

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