11

I need to have a list of all available view modes for an entity type so I can use it as the #options in a select field.

Any ideas? Thanks

2 Answers 2

14

I think you are talking about view modes for entities.

$entity_info = entity_get_info('node');
debug(array_keys($entity_info['view modes']));

It would result as

array (
  0 => 'full',
  1 => 'teaser',
  2 => 'rss',
  3 => 'search_index',
  4 => 'search_result',
)
0
2

You may also want to use this function...

field_view_mode_settings($entity_type, $bundle);

https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_mode_settings/7

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.