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:
- Working with the Entity API
- Add $EntityType::load() and loadMultiple() to simplify loading entities
- EntityInterface::load(), loadMultiple() and create() added to load and create new entities
Proposed resolution
- 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).
- If one is recommended, update documentation, change record, etc.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.