I made a custom view mode in Display Suite and I would like to use it as the default view mode for a given content type. Can anybody enlighten me as to how to do it?


This is the way i set the 'fullpage' view_mode of a node as default:

 * Implements hook_entity_view_mode_alter().
function YOUR_MODULE_entity_view_mode_alter(&$view_mode, $context) {
  // Set default view mode.
  if (isset($context['entity']->nid)) {
    if ($context['entity_type'] == 'node' && $context['entity']->type == 'YOUR_CTYPE' && $view_mode == 'full') {
      $view_mode = 'fullpage';

It actually sets the view_mode to 'fullpage' when in full mode (default), but you could ommit that part (&& $view_mode == 'full').

Remember that 'fullpage' is the machine name of my view_mode and 'YOUR_CTYPE' is the machine name of your content type.

Not sure if this will work with Display suite though...

|improve this answer|||||
  • DS is for Display Suite - i just edited the original question and I'll try your suggesion – Dalmaz Jul 1 '14 at 13:30
  • Yes it does! Just for the record: I created a custom module in sites/all/modules/custom/, created an .info and a .module file, to which I pasted the code above, replacing the module name with the one I chose and YOUR_CTYPE with the machine name of the content type (I emphasize that because i first just typed the human name and it obviously did not work). Thanks! – Dalmaz Jul 1 '14 at 13:58
  • And it seems to work consistently with Display Suite, i can change the default view mode in code to some new one created in DS. – Dalmaz Jul 1 '14 at 14:10
  • 1
    Great, there was no particular reason this won't work with DS, just never used it.Glad it helped. – Pan Chrono Jul 1 '14 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.