List enabled view modes (view displays) for a bundle of an entity type
Issue:
A developer needs to find which bundles of a given entity type have a specific view mode enabled – for example, to conditionally apply logic only to bundles where a teaser or custom view mode is configured.
Solution:
This snippet finds all bundles for a certain entity type which have a certain view mode enabled.
Example: Find all node bundles that have a teaser view display.
→ php $this->getBundlesWithViewmode('node', 'teaser'); Result: php ['article', 'blog']