Drupal 8 entities inheritance and bundles I have 2 questions about entities inheritance and bundles in Drupal 8.


Let's assume that I have a content entity called "foo" (entity type) and "foo" as its bundle, and now I want to create the content entity "bar" with the bundle "foo", and add new properties to it. Is it possibile?
Is it possible to use inheritance with content entities, something like the following inheritance (and if so, is that considered to be a bad practice?)
:

class foo extends ContentEntityBase {}

class bar extends foo{}

class baz extends bar{}
Drupal Core uses that itself for test entity types:



So yes, this works. However, it only works as far as it is covered by PHP. You can inherit base field definitions for example if you call the parent method and use the return value, see those classes.

Annotations for example are however not inherited, each subclass needs to re-define everything.

There is the plan to provide a default content entity that will a default set of base field definitions and other things that you probably want to have on custom entity types, likely that will live in the 8.x version of the entity.module.

On what you want to use, that depends on your use case. The common use case for bundles is so that users/site builders can create them and add configurable fields. If you need that, use them.

Keep in mind that not everything is generic, various things are still node specific, like the whole revision handling (the storage is generic, but all the user interfaces require a ton of custom code at the moment), the node preview functionality is also custom and other things. We plan to improve that situation in the mentioned entity.module until we can improve it in core.