Drupal - When is it appropriate to create an Entity versus just adding a new content type?

It's not so much about what the benefits are but more about what's appropriate for a particular situation like you've said. You can represent pretty much anything with a node and for 99% of situations (as I've found at least) you won't need to implement custom entity types.

I always think of the taxonomy_term entity type as a good example of why not everything should be a node/content type:

A taxonomy term is essentially for grouping together different entities and as such doesn't require the same functionality as a node. While you could theoretically use a content type to perform this functionality (with perhaps a node reference field), a taxonomy term doesn't need to do the same thing as a node so it doesn't really make sense to do so. The same can be said for the user and taxonomy_vocabulary entity types.

So a taxonomy term is created as a separate entity and is programmed to do only what it needs to, while still getting the benefits of being able to have fields attached, etc.

I think the simple answer is that when a node/content type doesn't do what you need it to, or it's just a massive amount of overkill/overhead for very little benefit, then you should choose to write a custom entity.

This is only based on my personal experience; I'd be interested to hear what someone directly involved with Drupal core development had to say about this.


A very simple rule of thumb I use is whether your content need to be publicly displayed on its own. If so, then go for node, if not choose an entity. Entityforms now allows you to create an interface to fill out your entities.

For example, on a website made with D6 we build an advertisement content type (with its image field, begin/end display date...), but then you have to make it not published by default and give your editors the rights to edit/view these node and hoped no views/search will display these on the outside world. It's quite cumbersome and it would be easier to deal with entities.


An entity represents a specific use case.

I believe the credit for this simple definition goes to Fago, but I'm to lazy to find a reference.

We could use Content (aka Nodes) for all use-cases if we wanted to, but often that doesn't make sense.

Content has an author and settings for both comments and menu location.

Users, represent a use case different enough from Content because on a user neither of the above makes any sense, while on the other hand, a user must have an e-mail and a password.

Taxonomy terms stand out because they have the built in functionality to be arranged in a hierarchy, even a circular one.

If your use-case is similar enough to an existing entity, go with using that entity. If your entity is governed by significantly different rules than any existing ones though, create a new one.

There is also An Introduction to Entities, but unfortunately it doesn't really answer your question.

Tags:

Entities