Field

In Drupal, a field stores one kind of data on an entity; its type, widget and formatter decide what is stored, how it is entered and how it is shown.

Learn DrupalDrupal glossary

A field is one named piece of data on an entity, such as a body text, an image, a date or a link to another item. Every field has a field type that decides which kind of data it holds. Administrators add fields to entity sub-types such as content types, so every item of that sub-type has the same fields to fill in.

How fields work in Drupal 11

A field has three parts. The field type defines what is stored; core ships types such as string (labeled Short text) and entity_reference. The field widget is the form control editors use to enter the data. The field formatter decides how the data is displayed. A field type can name a default widget and a default formatter; for string they are string_textfield and string.

Fields come in two kinds:

  • Base fields are defined in code through the static baseFieldDefinitions() method of an entity type. By definition they exist for every bundle.
  • Configurable fields are the ones you create in the Field UI module. Each one is stored as configuration: a field storage (field.storage.*) that holds the type and storage settings, and a field (field.field.*) that attaches it to one bundle. Both can be exported with configuration management.

The Field UI help separates two groups of settings. Field-level settings depend on the field type and affect how the data is stored. Sub-type-level settings belong to each bundle that uses the field and can be changed later; the label, help text, default value and the required flag are examples. The machine name of a field cannot be changed once the field exists.

Example

The Drupal User Guide adds a website address to a Vendor content type. Go to Structure › Content types and click Manage fields for Vendor. Add a Link field with the label Vendor URL. Drupal generates the machine name from the label, and you can change it before you save. In the field settings, the guide leaves the field optional and permits external links only. After you save, every Vendor item has a Vendor URL input.

Common mistakes

  • Creating a second field for the same data. Reuse the existing field on the other content type instead. Reuse works across bundles of one entity type only.
  • Treating the label as the identifier. Code and configuration use the machine name, so choose it before you save.
  • Looking for a missing field in the wrong place. A field can exist on the edit form and still not show on the page. In a view mode, each field can be hidden through the formatter drop-down on the Manage display page.
  • Mixing up the three parts. The widget changes the edit form and the formatter changes the output. Changing either one does not create a new field.

For marketing and content teams

Fields turn a page into structured data. Instead of one large text area, a case study can have a customer name, a logo, a result and a link, each in its own field. That makes it possible to reuse the same data in lists, teasers and search results. When you need a new piece of data, tell your site builder what it is (text, number, date, image, link, a choice from a list) and where it should show. That decides the field type.

With DXPR

DXPR Builder works on a formatted text field, such as Body. You open Manage display for a content type and change the format of that field to DXPR Builder; after that, editors build the field's content visually. See DXPR Builder.

Sources

Questions about Field

A field is one named slot on an entity, such as a subtitle. The field type decides what kind of data the slot holds, such as short text, a date or an image. Core and modules provide the field types; you choose one when you create the field.

Yes, within the same entity type. The Field UI help says a field made for the article content type can be reused on the page content type, but not on content blocks or taxonomy terms. The Manage fields page lets you pick an existing field to reuse.

Go to Structure › Content types and click Manage fields for your content type. Other entity types, such as taxonomy vocabularies, have their own Manage fields page.

A base field is defined in code by the entity type and exists on every bundle of that entity type. A field you add on a Manage fields page is a configurable field, which belongs to the bundles you add it to.

Related terms

All Drupal terms from A to Z