Drupal admin: Changing the default Open or Collapsed state of filters and fieldsets in Node editing screens

As you add modules to Drupal, the “Edit” screen of each node can start piling up a lot of optional filters and settings that you can apply to the node. These include comment settings, input filters, image pickers and browsers, authoring settings, etc. The general term for all these added features on the node edit screen is “fieldsets.”

Most of them are collapsed when you first open the screen, which makes it easy to scroll down to the “submit” button or the lower fieldsets. However some modules set themselves to be open by default. This can be a problem if you have to edit a lot of nodes – it causes a lot of extra scrolling and is visually confusing.

Here is how I changed that setting in the Imagepicker module.

I store the modules in the /mysite/sites/all/modules/ folder.

In /mysite/sites/all/modules/imagepicker/imagepicker.module I searched for “collaps” and found this function:

function imagepicker_form_alter($form_id, &$form) {
if (imagepicker_get_access()) {
if (preg_match('/node_form$/i', $form_id)) {
$form['body_filter']['file_upload'] = array(
'#type' => 'fieldset',
'#title' => 'Image picker',
'#collapsible' => 1,
'#collapsed' => 0,
'#weight' => 1,
'#validate' => array(),
'#theme' => 'imagepicker_iframe',
1 => array()
);
}
}
}


Changing

'#collapsed' => 0,

to

'#collapsed' => 1,

sets the default view of that fieldset to collapsed.