Change the view mode of an entity that is being displayed.
string $view_mode: The view_mode that is to be used to display the entity.
array $context: Array with contextual information, including:
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_entity_view_mode_alter(&$view_mode, $context) {
// For nodes, change the view mode when it is teaser.
if ($context['entity_type'] == 'node' && $view_mode == 'teaser') {
$view_mode = 'my_custom_view_mode';
}
}