I have a design question:
I have several models that lend themselves to inheritance very well.
I have an
animal object that has attributes that are shared between the
hamster objects very nicely. However, the source of the
hamster are all from different APIs.
So what I started doing was to build my module around each of the APIs, with the necessary 'fields' effectively hardcoded in the module
animal. I knew that this horrifically violates the DRY principle; but am from the D6 (barely D7 era and hadn't really been introduced to entity types). This was using custom tables, and custom 'models'. This also means that I have to create the views, and all the other stuff associated with it myself.
So then I realized that I could actually use
entity types for this. The core
animal module exposes only what it needs to (a small set of fields). And the
hamster modules all extend the
animal entity type thus giving me access to all the shared data without having to repeat myself and the added bonus of having views, handlers and the other stuff for almost free (a bit of boilerplate that is copy and paste...).
My questions are thus:
- Is this thinking right, that content entity types are the way to go?
- I know what I gain, but what do I lose by doing this?
- Is this a good approach, i.e. is it fair to extend a base entity type?
- Is it better to create
bundlesfor each of the
hamsteror just use the extending of the
- When do you use a bundle vs extending a content type?