Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
entity_load(), entity_load_multiple_by_properties(), entity_load_unchanged() and entity_load_multiple() are marked as deprecated in Drupal 8, and will be removed before Drupal 9. Prior to removing the functions, we need to remove all usages
Proposed resolution
We will have separate subtask for every known "static" entity type (i.e. type that we know before the code is executed).
With every static entity type:
- Use entity type-specific controller to load entity(entities)
- entity_load('action', $id) => Action::load($id)
- entity_load_multiple('action', $ids) => Action::loadMultiple($ids)
- entity_load_multiple_by_properties('action', $ids) => Action::loadByProperties($ids)
- When we need to reset the entity cache, use EntityTypeManager->getStorage($entity_type)->resetCache()
- To obtain EntityTypeManager object in tests, use $this->container->get('entity_type.manager')
- To obtain EntityTypeManager in all other places, use \Drupal::entityTypeManager()
For dynamic entity type, use EntityTypeManager->getStorage() for loading entities.
Remaining tasks
- Create subtasks for specific entity types
- Create a subtask to replace usage for dynamic entity types
- Make sure that using DI container doesn't break the tests
User interface changes
No UI changes
API changes
No API changes at this time
Data model changes
No data model changes
Comment | File | Size | Author |
---|
Comments
Comment #1
Mukeysh CreditAttribution: Mukeysh commentedPatch addded for the above
Comment #2
daffie CreditAttribution: daffie commentedI have put this issue to postponed, because the issue #2322639: Replace all instances of node_type_load(), node_type_get_types(), entity_load('node_type') and entity_load_multiple('node_type') with static method calls is not fixed. This issue removes all uses of node_type_get_types. It also removes the uses of node_type_load(), entity_load('node_type') and entity_load_multiple('node_type'). I think that is a good idea to remove those functions as well in this issue. So I am amending the issue title and summary.
@Mukeysh: The patch that you made only removes the function. It also has to remove the documentation that describes the function (Just above it).
Comment #3
Mile23During beta phase, it's unlikely these functions will be removed if they aren't already. The
entity_*()
ones aren't marked as deprecated: #2474151: Mark procedural wrappers in entity.inc as deprecatedComment #4
JeroenT@Mile23,
Those functions are deprecated for version 9.0 (https://www.drupal.org/node/2321969#comment-9867723).
Comment #5
catchThere are still 13 calls to entity_load_multiple() and 155 calls to entity_load() in 8.x - moving back to there to remove the usages. Removing the function we can do with a single patch that removes dozens of other deprecated procedural wrappers.
https://api.drupal.org/api/drupal/core!includes!entity.inc/function/enti...
https://api.drupal.org/api/drupal/core!includes!entity.inc/function/enti...
Comment #6
daffie CreditAttribution: daffie commented#2322639: Replace all instances of node_type_load(), node_type_get_types(), entity_load('node_type') and entity_load_multiple('node_type') with static method calls has landed. So back to needs work.
Comment #7
catchMore active I think, the patch doesn't remove usages of those two functions.
Comment #8
valthebaldThis should remove entity_load_multiple() and its usage
Comment #9
tstoecklerLooks beautiful and by removing the functions we now it works. The actual committable patch would have to leave the existing functions in until D9.
The one case in the patch that could use dependency injection instead of a call to
\Drupal::entityTypeManager()
iscore/modules/views/src/Plugin/views/query/Sql.php
but not sure we want to hold up the patch on that.Comment #10
Mile23Some more...
Needs to reset the cache.
Leave these in because they're deprecated for removal in 9.
Use $this->container in all the tests, instead of \Drupal.
Comment #11
valthebaldGoing to submit "fuller" patch with entity_load() calls removed as well
Comment #12
valthebaldChanges from the last patch (no sense in making interdiff, change is too big):
Comment #13
catchAs mentioned these hunks should be dropped from the patch - actual removal is 9.x
Didn't do a full review of the patch, but what I did review looked good.
Comment #15
valthebaldBring back entity_load() and entity_load_multiple() declarations - only replacing \Drupal->entityManager() with \Drupal->entityTypeManager()
Comment #17
valthebaldStupid typo
Comment #19
valthebaldComment #21
valthebaldDeclare config_test_no_status as a separately annotated class to avoid AmbiguousEntityClassException
Comment #22
valthebaldComment #23
valthebaldComment #26
valthebaldIt looks like using $this->container instead of global \Drupal object causes a lot of problems. The patch is already big enough, can the issue be split up? It can be replacing usage of entity_load() / entity_load_multiple() from "the base code", and then the same for the tests
Comment #27
valthebaldComment #28
valthebaldAdd entity_load_multiple_by_properties() and entity_load_unchanged() to the list of functions calls to which should be removed
Comment #29
catchSplitting into tests and non-tests sounds fine.
Comment #30
valthebald@catch: awesome!
non-test patch has been submitted in a child issue #2721771: Remove entity_load_multiple(), entity_load(), entity_load_unchanged() and entity_load_multiple_by_properties() usages from the code base (non-tests), and passes tests.
Comment #31
alexpottI'm not sure about the scope suggested in #29. Can't we just have an issue per function - because this makes things really easy to review.
Comment #32
valthebaldComment #33
valthebald@alexpott, as you suggested in #2721771: Remove entity_load_multiple(), entity_load(), entity_load_unchanged() and entity_load_multiple_by_properties() usages from the code base (non-tests), I start filing subissues based on entity type / module (not function, cause that's make patches unreasonably big and hard to review)
Comment #34
valthebaldChange status to Active, and unassign myself
Comment #35
valthebaldComment #36
Beau Townsend CreditAttribution: Beau Townsend as a volunteer commentedPatch for sub issue Remove entity_load* usage for 'editor' entity type (https://www.drupal.org/node/2723587).
Comment #37
Beau Townsend CreditAttribution: Beau Townsend as a volunteer commentedErrantly uploaded patch to wrong issue. Restoring status to needs work.
Comment #39
valthebaldBack to 'Active'
Comment #40
valthebaldBumping version (no need for backport)
Comment #41
Mile23New child issue: #2549789: Remove entity_load* usage for block_content entity type
Comment #46
volegerComment #47
alexpottSee #3027178-5: Properly deprecate entity_load_multiple_by_properties() we should have issues scoped to each method and add @trigger_error() to each method. The issue summary needs a bit of an update.
Comment #48
alexpottAdded #3028657: Properly deprecate entity_load_multiple()
Comment #50
BerdirComment #51
BerdirLooks like we are done here, thanks everyone who helped!
Comment #52
andypostThe leftover is RTBC already #3051069: Remove usage of deprecated entity_delete_multiple in core and trigger an error