Problem
At the Drupalcamp Vienna code sprints I've seen people doing stuff like
/**
* @var \Drupal\node\NodeInterface $node
*/
such that they are able to auto-complete on the methods and can work with it. That's necessary as calls like
$node = \Drupal::entityManager()->getStorageController('node')->load($id);
does not give you auto-completion.
Another problem with the above line is that you'll have to know about storage controllers, access controllers, view builders, etc. for being able to work with an entity type. But you shouldn't have to. It's fine that we use entity controllers for easy entity type construction and code-reuse, but that's not something a person working with an entity type should have to know about.
Finally, imo we want to have a single object that we can inject into entity class, instead of having to add separate dependency for each controller being used there as that makes for quite some code and is not efficient memory-wise (every class property increases memory usage). Instead, we could inject the entitymanager but you'd still have to do calls like $this->entityManager->getStorageController($this->entityType)->save($this);
- ouch. Instead, having a single per entity type manager class injected would be way more convenient.
Solution
Something along the lines of (to be figured out):
- Provide per entity type managers, i.e. NodeManager, CommentManager (exists!), UserManager, NodeTypeManager, ... and make all important methods available on it.
- Re-define methods critical methods as required for type-hints on it.
- Rename EntityManager to EntityTypeManager, as when you do $entity_manager->getDefinitions() it gets you definitions about entity types, not entities.