Skip to content

Services

Service Class Use
theme_view_display.lookup OverrideLookup Find overrides without loading entities.
theme_view_display.component_dependencies ComponentDependencyCalculator Provider dependencies of a source tree.
theme_view_display.theme_options ThemeOptions The themes that may have overrides, and theme labels.
theme_view_display.links DisplayLinks URLs of the override routes and the theme switcher.

All have an autowiring alias by class name.

OverrideLookup

$lookup = \Drupal::service('theme_view_display.lookup');

// ID of the enabled override, or NULL.
$lookup->getEnabledId('olivero', 'node', 'article', 'teaser');

// All overrides of a bundle: [mode => [theme => ['id' => ..., 'status' => bool]]].
$lookup->getOverrides('node', 'article');

// Every override, flat.
$lookup->getAll();

The map is cached. In a test that creates overrides, call reset() to drop the copy held in the request.

$links = \Drupal::service('theme_view_display.links');
$links->url('edit', 'node', 'article', 'teaser', 'olivero');   // add, edit, revert, toggle
$links->coreUrl('node', 'article', 'teaser');
$links->overviewUrl('node', 'article');
$links->switcher('node', 'article', 'teaser', 'olivero');      // render array

Hooks implemented

Hook Does
hook_entity_view_display_alter() Swaps in the override of the active theme.
hook_entity_view() Adds the cache tags.
hook_field_config_insert() Hides new fields in overrides.
hook_form_entity_view_display_edit_form_alter() Warning and switcher on the core form.
hook_entity_view_display_update() Message after saving the core display in the UI.
hook_runtime_requirements() The status report line.

Hook implementations are #[Hook] methods on classes in src/Hook/.