Let us start by establishing some basic terminology in order to prevent confusion down the line:
- Entities are instances of a given entity type. Thus, we can have one or more entities of a certain type, the latter being like a blueprint for the individual entities.
- Entity types can be of two kinds--content and configuration.
We talked a little bit about configuration entities in the previous section. There, we saw they are multiple instances of a certain type of configuration, as opposed to simple configuration, which is only one set of configuration values. Essentially, configuration entities are exportable sets of configuration values that inherit much of the same handling API as content entities.
Some examples of configuration entity types:
- View: A set of configuration values that make up a view
- ImageStyle: Defines how an image needs to be manipulated in that given style
- Role: Defines a role that can be given to a user
Content entities, on the other hand, are not exportable and are the most important way we can model and persist data in Drupal 8. These can be used for content and all sorts of other structured data used in your business logic that needs to be persisted but not deployed to the next environment.
Some examples of content entity types:
- Comment
- User
- Taxonomy Term
Apart from the exportability aspect, the main difference between the content and configuration entities is the type of fields they use. The latter uses simpler fields, the amalgamation of which gets stored as one entity "record" in the database (and exported to YAML), while the content entity fields are complex and structured both in code modeling and in the persistence layer (the database).
Moreover, configuration entities also lack bundles. Bundles are yet another categorization of entities that sits below the content entity type. That means that each content entity type can have (but they does not have to have) one or more bundles, onto which configurable fields can be attached. And not to throw more confusion at you but bundles are actually configuration entities themselves as they need to be exported and can be multiple of them.
The Entity API is very flexible in terms of the types of data that you can store. Content entity types come with a number of different field types for various forms of data, from primitive values to more complex ones such as date or entity reference. We will see some examples later on.
Content entities can also be made revisionable. This means content entity types can be configured to keep in store older versions of the same entity with some extra metadata related to the change process.
In this section and going forward, I will illustrate the most common features of entities by way of exemplifying two entity types:
- Node: The most prolific content entity type that comes with Drupal core and that is typically used as the main content modeling entity type
- NodeType: The configuration entity type that defines Node bundles
In the next chapter, we will learn how to create our own. But after everything we will learn here, it will be a breeze.