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 now deprecated so we shouldn't use it anymore. When the entity type is known we should directly call <EntityType>::create()
. When the entity type is variable, we should use \Drupal::entityManager()->getStorage($entity_type)->create($values);
.
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 |
---|---|---|---|
#9 | interdiff-2503409-7-9.txt | 505 bytes | dimaro |
#9 | replace_deprecated-2503409-9.patch | 10.77 KB | dimaro |
#7 | interdiff-2503409-6-7.txt | 987 bytes | dimaro |
#7 | replace_deprecated-2503409-7.patch | 10.81 KB | dimaro |
#6 | replace_deprecated-2503409-6.patch | 10.88 KB | lluvigne |
Comments
Comment #1
DuaelFrComment #2
DuaelFrAs @alexpott said in #2494775-8: Replace deprecated usage of entity_create('action') with a direct call to Action::create(), this issue and it's meta are now postponed to Drupal 8.1.
Comment #3
Mile23Patch in #1 does not apply.
Comment #4
naveenvalechaAdding few appropriate tags
Comment #5
naveenvalechacorrecting title.
Comment #6
lluvigneRerolled #1. Hope that everything's ok.
Comment #7
dimaro CreditAttribution: dimaro at La Drupalera by Emergya commentedRemove unused namespace.
I checked with my IDE and its fine, there's no occurance left.
RTBC?
Comment #8
DuaelFrNice work here!
There is no occurence of
entity_create('block*
remaining.One last little nitpick, though.
This is not related to this issue and it seems not used anywhere in this file.
Comment #9
dimaro CreditAttribution: dimaro at La Drupalera by Emergya commentedUpdate the patch to fix this little nitpick.
Thanks @DuaelFr.
Comment #10
DuaelFrIf testbot is happy, that's RTBC for me :)
Comment #11
Mile23Applies, fixes problem, yay.
Comment #12
naveenvalechaRTBC +1, My IDE is happy.
Comment #13
catchCommitted/pushed to 8.1.x, thanks!