I need to get all possible viewmodes of a specific entity/bundle in D8. Currently I have this:

$viewmodes = \Drupal::service('entity_display.repository')->getViewModes($entity_type);

This shows all viewmodes on an entity, it doesn't filter on bundle. Also, the default viewmode is never included here.

Anyone knows a better way?

Cheers, Tom

2 Answers 2


What @googletorp said is correct. But there is a concept of "enabled" view modes, just not like you're apparently expecting.

Enabled view modes are view displays. Enabling a view mode for a given bundle creates a view display which then stores the formatter configuration.

Same for form modes and form displays.

And I think \Drupal\Core\Entity\EntityDisplayRepository::getViewModeOptionsByBundle() will kind of give you what you're looking for. The view modes for which the given bundle has a view display.

  • Ah, exactly that. Strange that I didn't see that method. :p Thanks
    – betz
    Apr 2, 2016 at 1:23

Your question is wrong :)

The thing with entity view modes is that they are created for a specific entity type, and will work on all bundles for that entity type.

A good example of this, is that all node types have the same view modes possible, you can select which ones you want to customize, but all of them will be available on all node types, if one isn't customized, the default is used instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.