In this article, we’ll discuss the drupal entity reference’s definition, how to create an entity reference in drupal, and what exactly an entity reference can refer to.

1. Definition

1.1 Entity

In Drupal, an entity is an item of either content or configuration data. Generally speaking, this term often refers to content entities. Examples of content entities are content items, comments, custom blocks, taxonomy terms, and users; examples of configuration entities are definitions of content types.

1.2 Entity Reference

Conceptually, entity reference provides a way for an entity to refer to another entity. An entity has fields. So from the implementation perspective, entity reference is simply a field type. Entity A can add a field, which refers to entity B. Effectively, entity B is referenced by entity A.

2. Is there an Entity Reference Module?

There used to be a separate entity reference module. Since Drupal 8, the entity reference module became deprecated. Its functionalities have been split and moved to various other modules. As of Drupal 10, the Field module has built-in entity reference. You may check its help document at https://yourdomain.com/admin/help/field. Or navigate to Manage->Extend->Field, then click help.

field module contains drupal entity refernce

3. How to Create an Entity Reference?

There are quite a few places in Drupal 10 you can add a field to an entity. These are also the places you’ll be able to create an entity reference.

1. Create for Content

Navigate to Administration -> Structure -> Content types -> Edit any content type -> Manage fields.

add drupal entity reference for content

2. Create for Comment

Navigate to Administration -> Structure -> Comment types -> Edit any comment type -> Manage fields.

add field for comment

3. Create for Taxonomy Term

Navigate to Administration -> Structure ->Taxonomy -> Edit any vocabulary -> Manage fields.

add field for taxonomy terms

4. Create for User

Navigate to Administration -> Configuration -> People -> Account settings -> Manage fields.

add entity reference for user

5. Create for Custom Block

Navigate to Administration -> Structure -> Block layout -> Custom block library -> Block types -> Edit any block type -> Manage fields.

add field for block

Now, we know five types of entities that can add an entity reference. Once again, they are content, comment, taxonomy term, and custom block.

4. What can an Entity Reference Refer to?

In any above places, when you click ‘Add field’. You’ll have the opportunity to add a reference to one of the following common referents – content, file, image, taxonomy term, or user.

entity reference type

Choose ‘Other…’ and on the next screen, click ‘Type of item to reference’. Then, you’ll able to see all the possible entity types in the current Drupal version and make a reference to any of these.

Type of items to reference

The following table lists all available entity types for Drupal 10.0.7 released on Mar-24-2023. Please note, those entities are related to the modules you have installed, as new modules might introduce new entities. For example, ‘Content Language Settings’ is introduced by one of the Multilingual modules. So you won’t be able to see this entity if you have not installed those modules,

ContentConfiguration
commentAction
contentBase field override
custom blockBlock
custom menu linkComment type
FileContact Form
Shortcut linkContent Language Settings
Taxonomy termContent type
URL aliasCustom block type
UserDate format
Entity form display
Entity view display
Field
Field storage
Form mode
Image style
Language
Menu
Role
Search Page
Shortcut set
Taxonomy vocabulary
Text Editor
Text format
Tour
View
View mode

Next

In the next tutorial on Drupal entity reference, we’ll continue to explore what happens when we use entity reference. We also provide some other drupal tutorials.

[Disclaimer: Featured image was proudly generated by Midjourney.]

Leave a Reply

Your email address will not be published. Required fields are marked *