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 |
---|---|---|---|
#16 | replace_deprecated-2669926-16.patch | 8.98 KB | dimaro |
#11 | replace_deprecated-2669926-11.patch | 9.63 KB | kostyashupenko |
#8 | 2669926-8.patch | 8.26 KB | felribeiro |
|
Comments
Comment #2
naveenvalechaComment #3
felribeiro CreditAttribution: felribeiro at CI&T commentedComment #4
Mile23Thanks for working on this.
We only want to work on entity type names starting with taxonomy. The other entity types have their own separate issues.
Comment #6
felribeiro CreditAttribution: felribeiro at CI&T commentedComment #8
felribeiro CreditAttribution: felribeiro at CI&T commentedComment #10
naveenvalechacorrecting title.
Comment #11
kostyashupenkoRerolled #8
Comment #12
naveenvalechawe have 1 left in core/scripts/generate-d7-content.sh but we can leave this for now ?
All looks good to me. RTBC +1
Not sure about this documentation change.
Comment #13
dimaro CreditAttribution: dimaro at La Drupalera by Emergya commentedMaybe we should keep the comments in HEAD?
But I'm not sure...
Comment #14
Mile23Yah we definitely want to keep the documentation, unless it's wrong, in which case the solution is to make it correct. :-)
Comment #15
naveenvalechaThanks for confirming paul
Comment #16
dimaro CreditAttribution: dimaro at La Drupalera by Emergya commentedRerolled #8 again and only keep the comments in HEAD.
Comment #17
naveenvalechaPerfect Thanks! taken care #12
An interdiff is really helpful https://www.drupal.org/documentation/git/interdiff
Comment #18
naveenvalechaif we really need documentation change, please file another issue.
Comment #20
catchCommitted/pushed to 8.1.x, thanks!
Comment #21
AjitSRemoving the 'novice' task.
Comment #22
naveenvalechaits not worth to remove that tags after issues gets committed.
Comment #23
naveenvalechaoops my ide missed deprecated function at few places :( filed a new issue #2672604: Replace deprecated usage of entity_create('taxonomy_term') and entity_create('taxonomy_vocabulary') with a direct call to Term::create() and Vocabulary::create()
single slap to my IDE