As developers, time after time, we come across numerous terms that gain a new meaning in the context of which technology we're using them. Moreover, a lot of times, you'll find that certain terms mean one thing on one platform and something else in another!
Drupal, itself, is no different, as it has many different terminologies that are used in the community. Entities are definitely one to consider when picking up on Drupal terminology (not to be confused with entities in the Symfony framework in which Drupal 8 is now built). The term “entity” in Drupal is a term you will not necessarily come across often if at all if you're just site building. It is a term used mostly for the development aspect of Drupal to describe data.
So the question in mind is basically "What is an entity?" Before answering that question in the context of Drupal, let's first take a look at the actual meaning of the word entity. The Merriam-Webster definition is rendered as "the existence of a thing as contrasted with its attributes". This definition is very helpful when defining Drupal entities because that is basically what they are.
You could say...Drupal entities are pieces of content or data that have different attributes or metadata associated with it.
Yep, they are just individual items with unique attributes. Let's take application developers for example. They are all individuals with a set of abilities and attributes. They have specific goals or purposes they work to fulfill. Some develop applications for the web, some for desktops and laptops, and others for mobile devices, such as tablets and phones.
To drill deeper, we also have multiple varieties of application developers for each of the mentioned mediums. For the web, you can have front-end and back-end developers. Mobile developers often develop for specific operating systems like Android or iOS. You may also notice many applications that are only built for computers running Windows.
As you can see, although all of the groups mentioned above are still application developers, they do things differently and for different reasons using their varying abilities.
Entities are like individual "application developers" that have abilities and attributes (or fields) associated with them to fulfill a purpose. There are different types in which these abilities and attributes vary, and thus do a variety of different things. These types are referred to as entity types.
Drupal, as you may have imagined, comes with default entity types. As of the Drupal 8 releases, some of these are node (content), taxonomy term, user, comments, block, file, and the list continues. They all serve different purposes. The node entity type is intended specifically for the output of content where taxonomy term is meant for the grouping of content. Any instance of these entity types created with data input as defined by that entity type are individual entities.
Entities can also have subtypes, known as bundles. Entity types can further be divided into sub-groups with specific types of data for each while still maintaining overall the same functionality. For example, bundles for the node entity type are called content types and allow a user to define a specific set of fields for each. Drupal.org outlines the bundles for Drupal's core entities and even provides a diagram or map of the entities.
Based on the illustration above, a similar diagram would look like this:
Entities were initially introduced in Drupal 7 allowing content such as taxonomy terms and comments to receive fields via the new field API. Before Drupal 7, custom fields were added through the UI by way of a contributed module known as the Content Construction Kit (CCK). At that time, fields could only be added to nodes. As Drupal began to move away from a "page" centric view to a more "data" centric view, the concept of entities was created in D7 and a lot of the field functionality from the CCK module was used in the field API.
Now as of Drupal 8, more things than ever are entities giving site builders and developers more power to customize their projects to their particular needs!
Entities in Drupal 8 allow us to attach fields to and thus customize the output of different things, such as blocks and users, which was previously not possible. It gives us more control over the data we use throughout our projects and how we display it.
More entity types can be added by contributed modules, such as the Paragraphs module that adds the Paragraph entity type or the Media module which adds the Media entity type, both of which have unique capabilities. Moreover, you can add entity types of your own!
Drupal entities are just individual items that can be used in different ways to do a variety of things.
Hopefully, you have gained a better understanding of Drupal entities. There is one more thing. As mentioned earlier, entity types can be added by contributed modules, which means Drupal allows for the creation of more. Why would we ever need to do that? In fact, how would we build an entity type ourselves? These questions will be answered in a follow-up post!