Skip to content

Resolution and caching

Choosing the display

ThemeViewDisplayHooks::displayAlter() implements hook_entity_view_display_alter().

sequenceDiagram
    participant Core as EntityViewDisplay::collectRenderDisplays()
    participant Hook as displayAlter()
    participant Lookup as OverrideLookup
    Core->>Hook: display found (mode M or default)
    Hook->>Hook: skip if new, or already an override
    Hook->>Lookup: getEnabledId(active theme, type, bundle, display mode)
    Lookup-->>Hook: override ID or NULL
    Hook->>Hook: skip if Layout Builder, log a warning
    Hook-->>Core: new display built from the override
  1. The active theme comes from theme.manager.
  2. The override ID is looked up with the mode of the display core found, not the mode requested.
  3. With no enabled override, the display is returned unchanged.
  4. Otherwise a new entity_view_display is created at runtime from the override's content, hidden and third-party settings, and handed back in place of the core display.

A new object is built each time because the display must not carry the Display Builder settings of the override: Display Builder reads its sources from config by display ID, so it would render the sources of the core display. The theme_view_display_builder sub-module renders the sources of the override instead.

The runtime display carries a marker: the third-party setting theme_view_display / override, holding the override ID. It is never saved. See Integrating other modules.

The lookup map

OverrideLookup keeps one map, [theme][entity type][bundle][mode] => {id, status}, in cache.default. It is built from raw config, with no entity loads, and invalidated by the list cache tag config:theme_view_display_list. Nothing is loaded for a theme that has no override.

Cache metadata

hook_entity_view() adds config:theme_view_display_list to every entity build, and the override's own config tag when one applies. Creating, enabling or disabling an override therefore invalidates what rendered the core display. The theme is already a required cache context of the renderer, so the output varies by theme without help.

The tags are added in hook_entity_view() and not in hook_entity_display_build_alter(), because core merges the build of the display into the entity build without its top-level #cache.

Field lifecycle

  • hook_field_config_insert() hides the new field in every override of the bundle and saves them, unless the field is syncing.
  • Deleting a field removes it from the overrides through the config dependency, and the override stays.
  • ThemeViewDisplay::init() hides, in memory, components that are not known to a stored override.