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:

  1. Use entity type-specific controller to load entity(entities)
    1. entity_load('action', $id) => Action::load($id)
    2. entity_load_multiple('action', $ids) => Action::loadMultiple($ids)
    3. entity_load_multiple_by_properties('action', $ids) => Action::loadByProperties($ids)
  2. When we need to reset the entity cache, use EntityTypeManager->getStorage($entity_type)->resetCache()
  3. To obtain EntityTypeManager object in tests, use $this->container->get('entity_type.manager')
  4. To obtain EntityTypeManager in all other places, use \Drupal::entityTypeManager()

For dynamic entity type, use EntityTypeManager->getStorage() for loading entities.

Remaining tasks

  1. Create subtasks for specific entity types
  2. Create a subtask to replace usage for dynamic entity types
  3. 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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mukeysh’s picture

Patch addded for the above

daffie’s picture

Title: Remove deprecated function node_type_get_types() » Remove deprecated functions: node_type_load(), node_type_get_types(), entity_load('node_type') and entity_load_multiple('node_type')
Issue summary: View changes
Status: Active » Postponed
Parent 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

I 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).

Mile23’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue tags: +@deprecated
Related issues: +#2474151: Mark procedural wrappers in entity.inc as deprecated

During 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 deprecated

JeroenT’s picture

Version: 8.1.x-dev » 9.x-dev

@Mile23,

Those functions are deprecated for version 9.0 (https://www.drupal.org/node/2321969#comment-9867723).

catch’s picture

Title: Remove deprecated functions: node_type_load(), node_type_get_types(), entity_load('node_type') and entity_load_multiple('node_type') » Remove entity_load_multiple() and entity_load() usages
Version: 9.x-dev » 8.2.x-dev

There 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...

daffie’s picture

Component: node system » entity system
Status: Postponed » Needs work
catch’s picture

Status: Needs work » Active

More active I think, the patch doesn't remove usages of those two functions.

valthebald’s picture

Status: Active » Needs review
FileSize
21.27 KB

This should remove entity_load_multiple() and its usage

tstoeckler’s picture

Looks 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() is core/modules/views/src/Plugin/views/query/Sql.php but not sure we want to hold up the patch on that.

Mile23’s picture

Status: Needs review » Needs work

Some more...

  1. +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php
    @@ -204,8 +204,10 @@ protected function checkConfigurableLanguageWeight($state = 'by default') {
         /* @var $languages \Drupal\Core\Language\LanguageInterface[] */
    -    $languages = entity_load_multiple('configurable_language', NULL, TRUE);
    +    $languages = $storage->loadMultiple();
         foreach ($languages as $language) {
    

    Needs to reset the cache.

  2. +++ b/core/modules/node/node.module
    @@ -232,23 +232,6 @@ function node_mark($nid, $timestamp) {
    - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
    - *   Use \Drupal\node\Entity\NodeType::loadMultiple().
    - *
    - * @see \Drupal\node\Entity\NodeType::load()
    - */
    -function node_type_get_types() {
    
    @@ -293,22 +276,6 @@ function node_type_get_description(NodeTypeInterface $node_type) {
    - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
    - *   Use \Drupal\node\Entity\NodeType::load().
    - */
    -function node_type_load($name) {
    

    Leave these in because they're deprecated for removal in 9.

  3. +++ b/core/modules/rest/src/Tests/CsrfTest.php
    @@ -84,7 +84,9 @@ public function testCookieAuth() {
    -    $this->assertFalse(entity_load_multiple($this->testEntityType, NULL, TRUE), 'No entity has been created in the database.');
    +    $storage = \Drupal::entityTypeManager()->getStorage($this->testEntityType);
    

    Use $this->container in all the tests, instead of \Drupal.

valthebald’s picture

Assigned: Unassigned » valthebald
Issue tags: -Novice

Going to submit "fuller" patch with entity_load() calls removed as well

valthebald’s picture

Status: Needs work » Needs review
FileSize
185.89 KB

Changes from the last patch (no sense in making interdiff, change is too big):

  1. Remove usage of entity_load()
  2. In tests, use container instead of \Drupal object
  3. Following @todo in core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php, removed reset because #597236: Add entity caching to core is fixed
catch’s picture

+++ b/core/includes/entity.inc
@@ -53,42 +53,6 @@ function entity_get_bundles($entity_type = NULL) {
- */
-function entity_load($entity_type, $id, $reset = FALSE) {
-  $controller = \Drupal::entityManager()->getStorage($entity_type);

As 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.

Status: Needs review » Needs work

The last submitted patch, 12: 2359437-12.patch, failed testing.

valthebald’s picture

Status: Needs work » Needs review
FileSize
182.65 KB
4.61 KB

Bring back entity_load() and entity_load_multiple() declarations - only replacing \Drupal->entityManager() with \Drupal->entityTypeManager()

Status: Needs review » Needs work

The last submitted patch, 15: 2359437-15.patch, failed testing.

valthebald’s picture

Status: Needs work » Needs review
FileSize
182.65 KB
5.22 KB

Stupid typo

Status: Needs review » Needs work

The last submitted patch, 17: 2359437-17.patch, failed testing.

valthebald’s picture

Status: Needs work » Needs review
FileSize
182.65 KB

Status: Needs review » Needs work

The last submitted patch, 19: 2359437-19.patch, failed testing.

valthebald’s picture

Declare config_test_no_status as a separately annotated class to avoid AmbiguousEntityClassException

valthebald’s picture

valthebald’s picture

FileSize
6.35 KB

The last submitted patch, 21: 2359437-21.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 21: interdiff-19-21.patch, failed testing.

valthebald’s picture

It 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

valthebald’s picture

Issue summary: View changes
valthebald’s picture

Title: Remove entity_load_multiple() and entity_load() usages » Remove entity_load_multiple(), entity_load(), entity_load_unchanged() and entity_load_multiple_by_properties() usages
Issue summary: View changes

Add entity_load_multiple_by_properties() and entity_load_unchanged() to the list of functions calls to which should be removed

catch’s picture

Splitting into tests and non-tests sounds fine.

valthebald’s picture

alexpott’s picture

I'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.

valthebald’s picture

Issue summary: View changes
valthebald’s picture

@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)

valthebald’s picture

Assigned: valthebald » Unassigned
Status: Needs work » Active

Change status to Active, and unassign myself

valthebald’s picture

Title: Remove entity_load_multiple(), entity_load(), entity_load_unchanged() and entity_load_multiple_by_properties() usages » [meta] Remove entity_load* family of functions usage from the code base
Issue summary: View changes
Beau Townsend’s picture

Status: Active » Needs review
Issue tags: +neworleans2016
FileSize
8.74 KB

Patch for sub issue Remove entity_load* usage for 'editor' entity type (https://www.drupal.org/node/2723587).

Beau Townsend’s picture

Status: Needs review » Needs work

Errantly uploaded patch to wrong issue. Restoring status to needs work.

The last submitted patch, 36: 2723587-36.patch, failed testing.

valthebald’s picture

Status: Needs work » Active

Back to 'Active'

valthebald’s picture

Version: 8.2.x-dev » 8.3.x-dev

Bumping version (no need for backport)

Mile23’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

voleger’s picture

alexpott’s picture

See #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.

alexpott’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Berdir’s picture

Status: Active » Fixed

Looks like we are done here, thanks everyone who helped!

Status: Fixed » Closed (fixed)

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