Last active
December 29, 2015 02:09
-
-
Save miteshmap/7598376 to your computer and use it in GitHub Desktop.
Add custom View Mode for entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment