Skip to content

For developers

The module has no plugin type of its own. The extension surface is the theme_view_display config entity, a few services, and one runtime marker other modules can read.

Doing Read
Understanding which display renders, and the cache tags Resolution and caching
Adding dependencies or pruning after a removal Dependencies
Finding overrides, building links, listing themes Services
Making a module that reads displays by ID work with overrides Integrating other modules

Modules

flowchart TB
    Main[theme_view_display<br/>entity, lookup, UI, hooks, actions] --> DB[theme_view_display_builder<br/>buildable, builder route,<br/>preview theme]
    Main --> FG[theme_view_display_field_group<br/>groups in render and form]
    DB -.requires.-> DBM[display_builder_entity_view]
    FG -.requires.-> FGM[field_group]

The entity

Drupal\theme_view_display\Entity\ThemeViewDisplay extends core EntityViewDisplay, so content, hidden and third-party settings have the shape every other module reads.

Property Value
Entity type ID theme_view_display
Config prefix theme_view_display.display
ID {theme}.{entity_type}.{bundle}.{mode}, derived from its parts
Config export id, theme, targetEntityType, bundle, mode, content, hidden
Immutable id, theme, targetEntityType, bundle, mode

What it overrides, and why:

Method Reason
__construct() Requires theme, derives the ID, and reads the parts from an ID alone, as the createIfNotExists action passes it.
id(), set() Core assumes a three-part ID.
preSave() Refuses to save when the core display does not exist, and writes the ID.
init() Hides configurable components that appeared after the override was saved.
calculateDependencies() Adds the theme, the core display and the component providers.
onDependencyRemoval() Deletes the override with its theme or core display, and prunes sources of removed components.

Everything else is inherited, including the #[ActionMethod] methods that become config actions. Do not repeat the attribute on an override: the config action deriver registers each attribute and throws on a duplicate.

Useful API:

$override = ThemeViewDisplay::load('olivero.node.article.teaser');
$override->getTheme();            // 'olivero'
$override->getCoreDisplayId();    // 'node.article.teaser'
$override->getCoreDisplay();      // the core display, or NULL
ThemeViewDisplay::buildId('olivero', 'node', 'article', 'teaser');
ThemeViewDisplay::valuesFromDisplay($display, 'olivero'); // values to create a copy

Routes

Routes are generated for each entity type with a field_ui_base_route, from the Field UI route of the view mode, so bundle handling is the same. Without Field UI there are no such routes, and the subscribers add nothing. {base} is the Manage display path of the bundle.

Route Path
entity.theme_view_display.{type}.add {base}/display/{view_mode_name}/theme/add
entity.theme_view_display.{type}.edit .../theme/{theme}
entity.theme_view_display.{type}.revert .../theme/{theme}/revert
entity.theme_view_display.{type}.toggle .../theme/{theme}/toggle, CSRF protected
entity.theme_view_display.{type}.display_builder .../theme/{theme}/display-builder (Display Builder sub-module)
entity.theme_view_display.{type}.add_group, .delete_group .../add-group, .../delete-group/{field_group_name} (Field Group sub-module)

The default view mode uses the same routes with view_mode_name set to default.

The overview route of Field UI gets its controller replaced by a subclass that adds the column, because core has no alter point there. The route subscribers run after Field UI, Display Builder and Canvas. Canvas sets _controller on the view mode routes, so the route defaults copied from them drop it.

Tests

The module ships unit and kernel tests under tests/. The theme_view_display_test module provides an Extra Field plugin that prints a marker. Run them with the core test runner:

vendor/bin/phpunit -c web/core web/modules/custom/theme_view_display/tests/src