Skip to content

Instantly share code, notes, and snippets.

@miteshmap
Last active December 29, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miteshmap/7598376 to your computer and use it in GitHub Desktop.
Save miteshmap/7598376 to your computer and use it in GitHub Desktop.
Add custom View Mode for entity
<?php
/**
* Implements hook_entity_info_alter().
*/
function foo_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);
$entity_info['profile2']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);
}
/**
* Implements hook_preprocess_node().
*/
function foo_preprocess_node(&$vars) {
if ($vars['view_mode'] == 'another_teaser') {
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__another_teaser';
}
}
/**
* Implements hook_preprocess_entity().
*/
function foo_preprocess_entity(&$vars) {
switch ($vars['entity_type']) {
case 'profile2':
// Use different template
$vars['theme_hook_suggestions'][] = "profile2__{$vars['profile2']->type}__{$vars['view_mode']}";
$function_name = "foo_preprocess_profile2_{$vars['profile2']->type}_{$vars['view_mode']}";
if (function_exists($function_name)) {
$function_name($vars);
}
break;
}
}
html goes here.
<?php print $vars['defined_vars']; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment