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
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
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.
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff-2641626-4-9.txt | 819 bytes | heykarthikwithu |
#10 | 2641626-9.patch | 4.29 KB | heykarthikwithu |
#4 | view-2641626-4.patch | 4.02 KB | Mac_Weber |
Comments
Comment #2
Mac_Weber CreditAttribution: Mac_Weber as a volunteer commentedComment #4
Mac_Weber CreditAttribution: Mac_Weber as a volunteer commentedFixed class aliasing
Comment #5
Mac_Weber CreditAttribution: Mac_Weber as a volunteer commentedComment #6
Mac_Weber CreditAttribution: Mac_Weber as a volunteer commentedComment #7
Mile23Soooo close...
Patch applies, and gets all but one of the occurrences of
entity_load('view')
. It's inDisplayTest.php
.Rerunning the test anyway because that could be informative.
Comment #8
heykarthikwithuworking on this.
Comment #9
naveenvalechaThe issue title states this issue scopes only for the replacement of entity_create replacement.
Does this needs a new followup/existing issue already exist OR we need to push into this one ?
P.S. : #8 automatically got unassigned when submitting form. feel free to assign again but I have question on the scope of this issue
Comment #10
heykarthikwithuChanges as per #7.
@naveenvalecha, I have checked
DisplayTest.php
, their was anentity_create
,$view = entity_create('view')->getExecutable();
so i proceeded to give a patch, this might be a copy paste mistake by Mile23.
Comment #11
naveenvalecha#10, well make sense.
Here we go, applied patch locally and there was no entity_create left, Thanks!
Comment #13
catchCommitted/pushed to 8.1.x, thanks!