2

Under structure > content types > manage fields, there are display options in the upper right. The system-defined ones are "default" and "teaser" but I have seen "tokens" and "colorbox" added by contrib modules.

What hook or function do I use to give my modules access to create these new content type displays?

3

You can either use the Entity View Mode module (which lets you define new view modes through the UI) or you can use hook_entity_info_alter() in a custom module to create them through code:

function MYMODULE_entity_info_alter(&$info) {
  $info['node']['view modes']['some_view_mode'] = array(
    'label' => t('Some View Mode'),
    'custom settings' => TRUE,
  );
} 

The 'custom settings' bit is defined like this in the hook_entity_info() docs:

A boolean specifying whether the view mode should by default use its own custom field display settings. If FALSE, entities displayed in this view mode will reuse the 'default' display settings by default (e.g. right after the module exposing the view mode is enabled), but administrators can later use the Field UI to apply custom display settings specific to the view mode.

Basically you want to set the to TRUE to have the view mode show up on the manage fields page.

Using either of those methods you should see your new view mode(s) pop up everywhere (the manage display form for nodes, in views, etc.)

| improve this answer | |
  • Sorry pretty much answered at the same time. :) – junedkazi Sep 19 '12 at 17:55
  • No worries, there's extra info in your answer anyway so it's all good :) – Clive Sep 19 '12 at 17:58
3

You will have to use hook_entity_info_alter to add new view modes to existing entities. But if you creating new entity then you can do it in the hook_entity_info itself.

function MYMODULE_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['another_teaser'] = array(
    'label' => t('Another teaser'),
    'custom settings' => TRUE,
  );
} 

Also have a look at node_entity_info() if you want to define it in your own entity type.

| improve this answer | |

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.