Mario. Web Developer, Snowboarding Addict

Add custom view modes in Drupal 7

You can add extra display modes using hook_entity_info_alter.

Say you have a custom module 'myModule' and want to add a custom view to the node entity:

<?php
    function myModule_entity_info_alter(&$entity_info) {
        $mymode = array(
            'label' => 'My Custom Mode',
            'custom settings' => 'TRUE'
        );
        $entity_info['node']['view modes']['mymode'] = $mymode;
    }
?>

Flush caches and this should show up as a customisable view mode on the 'manage display' page of any node content type.

Tags:  tidbit drupal7

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <div> <h3> <h4>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <drupal5>, <drupal6>, <javascript>, <php>, <text>.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.