4

In my code, I need to get a list of all the view modes defined for nodes.

In Drupal 7, it was available via entity_get_info(). What is the equivalent method for producing a list of available view modes in Drupal 8?

8

View modes are config entities, so an entity query would do the trick:

$view_modes = Drupal::entityQuery('entity_view_mode')
  ->condition('targetEntityType', 'node')
  ->execute();
| improve this answer | |
  • It is no (longer ?) entity_view_mode but entity_view_display. You can also specificate the bundles with ->condition('bundle', ['full', 'teaser'] – Pierre Noel Jun 13 '19 at 14:28
  • @PierreNoel It's still entity_view_mode to get view modes... entity_view_display is something different (when you want to get the settings for how fields are displayed within a particular view mode) – Clive Jun 13 '19 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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