I rarely use the labels of a content type. It would be very nice to have all labels hidden by default for all existing and new content types. Is it possible to make a hook or something to add this as a default setting?

Comments

sammarks15’s picture

Which labels are you referring to? The labels that are displayed when editing content, or the labels that are displayed when rendering a node?

brian_c’s picture

Can't imagine why you'd want to hide all labels from the editing form.

So I'm pretty sure he means the rendered labels. I completely agree... 99% of the time after defining fields the first thing you do is go to Manage Display and set all the labels to "Hidden", it's a huge PITA and I wish there was a way to just default labels on new fields to Hidden.

Here is a hook that accomplishes exactly that:

// implementation of hook_field_create_instance()
// sets all labels to Hidden for new fields
function MODULENAME_field_create_instance($instance){
  // fetch the instance info
  $instance_info = field_info_instance(
    $instance['entity_type'],
    $instance['field_name'],
    $instance['bundle']
  );
  
  // set label in each display to hidden
  foreach( $instance_info['display'] as &$display ){
    $display['label'] = 'hidden';
  }
  
  // save back to disk
  field_update_instance($instance_info);
}

(Bizarrely, $instance does not contain all of the instance settings that were just written to disk, so we have to load & save them ourselves)

mtift’s picture

Component: configuration system » field system

There will be a configuration system in Drupal 8, but not Drupal 7.

dcam’s picture

Category: Feature request » Support request
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Lukas von Blarer’s picture

How can this be achieved in D8?