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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mac_Weber created an issue. See original summary.

Mac_Weber’s picture

Status: Needs review » Needs work

The last submitted patch, 2: field_storage_config-2641586-2.patch, failed testing.

Mac_Weber’s picture

Status: Needs work » Needs review
FileSize
109.93 KB

Fixed class aliasing

swentel’s picture

Status: Needs review » Needs work
Mac_Weber’s picture

Status: Needs work » Needs review
FileSize
110.23 KB

rerolled

Status: Needs review » Needs work

The last submitted patch, 6: field_storage_config-2641586-6.patch, failed testing.

Mac_Weber’s picture

Status: Needs work » Needs review
FileSize
109.94 KB

There was an error at the last patch.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quickfix

Applied, searched for entity_create('field_storage_config' and <code>entity_create("field_storage_config". Zero matches after this patch is applied.

Hence RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: field_storage_config-2641586-8.patch, failed testing.

Wim Leers’s picture

Issue tags: +Needs reroll, +Novice, +php-novice

Seems like something changed in the mean time:

error: patch failed: core/modules/image/src/Tests/ImageFieldTestBase.php:69
error: core/modules/image/src/Tests/ImageFieldTestBase.php: patch does not apply
Patch Failed to apply
Berdir’s picture

Component: entity system » field system

The last submitted patch, 8: field_storage_config-2641586-8.patch, failed testing.

marvin_B8’s picture

marvin_B8’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 14: field_storage_config-2641586-14.patch, failed testing.

marvin_B8’s picture

Status: Needs work » Needs review
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Hurray, green again!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x, thanks!

  • catch committed d4e7281 on
    Issue #2641586 by Mac_Weber, marvin_B8: Replace deprecated usage of...

Status: Fixed » Closed (fixed)

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

savkaviktor16@gmail.com’s picture

Issue tags: -Needs reroll