Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 37 ยท Content Types and Fields

Field Types, Widgets, Formatters and Display Modes

Understand how a Drupal field is edited and shown: field types, widgets for forms, formatters for output, view modes such as teaser, and form modes.

A Drupal field has three jobs that are deliberately kept apart: it has a type (what kind of data it holds), a widget (how an editor enters it) and a formatter (how a visitor sees it). The same stored value can be edited as a text box or as a select list, and shown as plain text, a link, or a badge, without changing the data. This separation is why site builders can restyle displays without touching content.

This lesson explains the three layers, introduces display modes (view modes and form modes), and shows how to configure them.

Field types

Core provides many field types, for example:

Type Stores Typical use
Text (plain) A string Short labels, places
Text (formatted) A string plus a text format Body copy
Number (integer, decimal, float) Numbers Capacity, price
Boolean True/false Online yes or no
Date and time A date or datetime Event start
List (text, integer) One of a fixed set Level, status
Link URL and title External resources
Email, Telephone Validated strings Contact info
Entity reference A pointer to another entity Author, category, media
Image, File An uploaded file reference Cover picture, PDF
Timestamp A Unix time Updated date

Contributed modules add more (address, geofield, paragraphs, and so on). The field type decides the database columns and the validation rules.

Widgets: the editing side

A widget turns a field into a form element. Each field type has several:

  • Text field or Text area (multiple rows) for strings.
  • Check boxes/radio buttons or Select list for lists and booleans.
  • Autocomplete or Select list for entity references.
  • Date and time picker widgets.
  • Image widget with preview and alt text.

You pick a widget in Manage form display (/admin/structure/types/manage/event/form-display). Each widget has settings such as size, placeholder or rows. You can also reorder and hide fields there.

Formatters: the viewing side

A formatter turns stored values into output. In Manage display (/admin/structure/types/manage/event/display) you decide, per field:

  • Whether it is visible and its label position (above, inline, hidden).
  • Which formatter to use: "Default" or "Plain text" for strings, "Trimmed" for a teaser, "Image" with an image style, "Entity reference label" with or without a link, "Date" with a chosen format.
  • The order of fields.

If a value is wrong on the page, ask: is the stored data wrong (type and widget side) or only its presentation (formatter side)?

View modes and form modes

Content is shown in different situations: a full page, a teaser in a list, a search result, a card. Each situation is a view mode. A node type can have a different set of formatters in each one: the Full content mode shows every field, while Teaser shows a trimmed summary and a small image.

Core includes modes such as Default, Full content, Teaser, RSS and Search index. You can add your own under Structure > Display modes > View modes (for example "Card") and enable them per content type under Custom display settings.

Form modes do the same for editing: you might offer a short "Quick add" form with only a few fields while the default form shows all.

flowchart TD
    V["Stored value: 2026-05-02T18:00"] --> W["Widget: date picker (edit)"]
    V --> F1["Formatter in Full: 'Saturday, May 2, 2026 at 6:00 pm'"]
    V --> F2["Formatter in Teaser: 'May 2'"]

One value, one widget, several formatters per view mode.

Display configuration in YAML

Each display is configuration. A shortened view display for the Event teaser looks like:

YAML
id: node.event.teaser
targetEntityType: node
bundle: event
mode: teaser
content:
  field_event_date:
    type: datetime_default
    label: hidden
    settings:
      format_type: short
    weight: 0
    region: content
hidden:
  field_capacity: true
  field_level: true

Here the teaser shows only the date, with its label hidden and a short date format; capacity and level are hidden.

A formatter pipeline you can run

This stand-in stores a raw value and applies different formatters per view mode. It is an illustration of the pattern, not Drupal's plugin system (which also works this way: formatters are plugins chosen by configuration).

JS Stand-in: formatters per view mode

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Change a formatter name in display.teaser to see how the output changes without touching the stored node.

Text formats and security

Formatted text fields use a text format (Basic HTML, Full HTML, Restricted). Formats define which HTML tags are allowed and which filters run. Give editors Basic HTML; reserve Full HTML for trusted roles, because it allows scripts and arbitrary markup. Drupal also escapes output by default in Twig, which protects against cross-site scripting.

Choosing widgets for good editing

  • Prefer select lists or radio buttons over free text for values from a fixed set.
  • Use autocomplete for references with many options and select for few.
  • Provide help text and sensible placeholders.
  • Group related fields with field groups (contributed module) to shorten long forms.

Picking widgets by number of choices

Here is a second stand-in: it suggests a widget based on the count of allowed values and the cardinality, a rule of thumb many site builders follow.

JS Stand-in: choosing a widget

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What controls how an editor enters a field value?

    Widgets render form elements on the editing screen, set in Manage form display.
  2. 2. Where do you choose how a field appears to visitors?

    Manage display configures formatters, labels and ordering per view mode.
  3. 3. What is a view mode?

    View modes let the same entity appear differently in different contexts.
  4. 4. Which text format should normal editors typically use?

    Basic HTML restricts tags and is safer; Full HTML is for trusted users.

Summary

  • A field has a type (data), a widget (editing) and a formatter (display).
  • Manage form display configures widgets; Manage display configures formatters per view mode.
  • View modes (Full, Teaser, custom) and form modes let one entity appear and be edited in several ways.
  • Use text formats carefully; restrict HTML for normal editors.

Next: Taxonomy and Entity References