Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 298347

Node::load($nid) vs. \Drupal::entityTypeManager()->getStorage('node')->load($nid)

$
0
0

Problem/Motivation

This issue is ONLY about known entity types and known entity classes. The 'node' entity type is used here only as an example, it could be 'user', 'filter_format', 'node_type', 'taxonomy_vocabulary' or any other config or content entity type. The issue uses the load() method as example but it refers also to loadMultiple() and create() methods.

Often I hear that \Drupal::entityTypeManager()->getStorage('node')->load($nid) should be used instead of Node::load($nid). Is argued that using the later is not recommended. I've searched in the relevant doc page, issue or change record but none of them could give me a clue why one is the preferred way, than the other:

Proposed resolution

  1. Clarify if one way is preferred over the other. Outline the cases when one way is prefered (remember, the entity type and entity class are known).
  2. If one is recommended, update documentation, change record, etc.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.


Viewing all articles
Browse latest Browse all 298347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>