Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I hope this is the right module queue for this question.
Is there a way I can change the options for a field's settings on the 'manage display' tab via code?
I'd like to change visibility and render mode, and maybe weight as well, for a particular custom field I have defined but don't want to use the GUI to make the change. This is so that in our environment I can more easily manage changes during our development process that won't require manual steps during our deployment window.
Ideally, I'd like to run this php code from a hook_update() function.
Thanks,
Cliff
Comments
Comment #1
tascWhen programmatically creating new taxonomy_vocabularies I need to have some additional fields on its terms. So I attach a field-collection-field and change the display-settings this way:
Comment #2
yan CreditAttribution: yan as a volunteer commentedThanks for the hint, tsc_a. So I think basically it's a combination of field_info_instance() and field_update_instance() as described on the update functions page:
To alter the display settings, that would be inside the
$instance_info['display']
array.For example, to hide the node body from teaser on a 'story' node type, you would use:
Comment #4
RAWDESK CreditAttribution: RAWDESK commentedThanks for #1 and #2 !
I've used this to update node field instance display settings, for newly created fields coming from a remote data feed.
Comment #5
ryanoreilly CreditAttribution: ryanoreilly commentedI've successfully been able to update the value of a display setting. I'm using a preprocess function to update the image style based on number of entities referenced. However, after node save, it's requiring a manual refresh in order for the updated display value to show.
The image style value is correct on node save, but the different image style won't display until the page is refreshed again after save. Any suggestions?