1

Let's say I have created a new view mode with DS. How can I activate it programmatically?

I want to achieve this because I'm doing an export with features but, despite the Features module exports DS settings and layouts, it does not automagically activate them. I'm planning to active this new display inside an install hook or something like that.

I looked in the tables schema, but I could not tell what activates a view mode.

1 Answer 1

1

Use following code to enable view mode programmatically in Drupal 7:

module_load_include('inc', 'field_ui', 'field_ui.admin');
$bundle_settings = field_bundle_settings('ENTITY TYPE', 'BUNDLE');
$bundle_settings['view_modes']['VIEW MODE']['custom_settings'] = TRUE;
field_bundle_settings('ENTITY TYPE', 'BUNDLE', $bundle_settings);

Replace ENTITY TYPE, BUNDLE, VIEW MODE with your values.

1
  • Thanks. I had the same code with a typo error... Anyway It worked, thanks :) Commented Jul 10, 2017 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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