1

When hook_installing a new custom node type filled with custom fields I call field_create_instance($instance) where I also set the custom fields' display like so:

'display' => array(
  'default' => array( // view mode
    'label' => 'hidden',
    'type' => 'text_default'
  ),
  'teaser' => array( // view mode
    'label' => 'hidden',
    'type' => 'hidden'
  )
)

I also added a body field via node_add_body_field($type) but where can I set that body's display properties programmatically? Per default it's set to be displayed in the teaser view. I want to hide it.

0

You can access and alter the view mode configuration via field_bundle_settings(), (which is basically a shortcut to variable_get and variable_set):

$bundle = 'my_node_type';
$bundle_settings = field_bundle_settings('node', $bundle);
$bundle_settings['view_modes']['teaser']['custom_settings'] = true;
field_bundle_settings('node', $bundle, $bundle_settings);
  • Is it possible this doesn't work for Drupal's body field? – leymannx Oct 14 '15 at 7:00
  • Body is a field just like any other (you can even remove it). A common problem during installation are stale caches. Try to run your steps over multiple processes/requests first. – Fabian Iwand Oct 14 '15 at 10:01

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.