Skip to content

Dependencies

ThemeViewDisplay::calculateDependencies() adds to what EntityDisplayBase already adds (bundle, fields, view mode):

Dependency Why
The owning theme The override is deleted with its theme, as a block is.
core.entity_view_display.{type}.{bundle}.{mode} The override copies it and needs it to exist.
Themes and modules providing the SDC components in the sources Uninstalling them must not leave a broken display.
Modules of third-party settings Added by core, for example display_builder and field_group.

Component providers

ComponentDependencyCalculator (service theme_view_display.component_dependencies) walks a Display Builder source tree, nested slots included, and collects the component ID of every node whose source_id is component. The provider is the part of the ID before the colon. It is a module if a module of that name exists, a theme if a theme does. An ID without an installed provider is skipped and logged, so a broken override can still be saved and repaired.

$calculator = \Drupal::service('theme_view_display.component_dependencies');
$calculator->calculate($sources);   // ['theme' => [...], 'module' => [...]]
$calculator->prune($sources, ['olivero'], ['some_module']);

The component is stored by ID in the display, while it lives in a theme or module. Core has no API for this yet; see #3484727.

Removal

onDependencyRemoval() runs when a dependency is removed:

  • The owning theme or the core display is removed: return FALSE, so the override is deleted.
  • A theme or module providing components is removed: remove the nodes using those components from the sources and return TRUE, so the override stays.
  • Fields and formatters: the parent behavior of EntityDisplayBase.