15 Sep 2013 18:18:23

Impelement custom entity view mode

To provide custom entity view mode you need to implement entity_info_alter_hook


/**
 * Implements hook_entity_info_alter().
 */
function pavelruban_entity_info_alter(&$entity_info) {
  // View modes for different entity types.
  $view_modes = array(
    'asset' => array(
      'teaser',
      'small_right',
      'tooltip',
      'slider_thumbnail',
      'slider_viewport',
    ),
    'user' => array(
      'comments',
    ),
  );

  // Check custom settings to provide admin settings
  // settings edit.
  foreach ($view_modes as $key => $entity_type) {
    foreach ($entity_type as $mode) {
      $entity_info[$key]['view modes'][$mode] = array(
        'label' => t(drupal_ucfirst(str_replace('_', ' ', $mode))),
        'custom settings' => TRUE,
      );
    }
  }
}

After implementing hook don't forget clear cache, then new view mode will be available to configure via admin interface panel.

Comments:

add comment

Image CAPTCHA