This snippet allows for the modification of Drupal fieldsets, which are groupings of fields of forms that can be collapsed or un-collapsed. This example uses the form for adding a page node and uncollapses the menu fieldset.

1. First, find the form's form_id by viewing the page's source in your browser (usually edit>>view source) or in Firebug. Search for "form_id" and the value in that is the form_id. The code should look something like this

<input type="hidden" name="form_id" id="edit-page-node-form" value="page_node_form"  />

Here the form_id is page_node_form
2. Find the form element and property. You can use the forms API reference or Devel module(turn on Display form element keys and weights (key=devel_form_weights, weight=0)" in the settings). The key is often simply the name of the fieldset and the property in this case is #collapsed which determines whether or not a field is collapsed. It can have the values true or false. If the value is true then the fieldset will be collapsed, if false it will not be collapsed.
3. Create a simple module by creating a folder in your sites/all/modules directory. Only two files are needed: modulename.info and modulename.module. The .info file should contain the basic information

name = Module Name
description = Un-collapse the menu fieldset
core = 6.x
version = 1.0

4. The .module file should have the code:

<?php
/**
 * Implements hook_form_alter().
 */
function MODULENAME_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
      case 'page_node_form':
       $form['menu']['#collapsed'] = FALSE;
       break;   
    }
  }
?>

The values to customize are the

  • MODULE NAME= name of module created
  • page_node_form if the form modified is different
  • menu if the module is un-collapsing another fieldset
  • FALSE= if the module's goal is to collapse a fieldset it should be TRUE instead

Comments

jdln’s picture

How can I do this for multiple content types? Do I need to make multiple modules?

Geijutsuka’s picture

I can't tell if this was answered (not knowing enough about php and the theme system), but how would you exactly do this for multiple content types? Would you put different "cases?" Thanks for helping a php-challenged themer out.

escoles’s picture

At Devel 6x-1.23, the configuration option given in step 2 has been moved the the theme_devel module, where it is available through a different vector. See here: http://drupal.org/node/832374#comment-3108022

aciy’s picture

Really appreciate this - I'm dealing a client who is very picky with what version hes using (so strange) stuck in the past..

escoles’s picture

How would you address nested fieldsets?

E.g., the Menu Attributes module creates a fieldset inside the Menu fieldset. You can't directly touch the collapsed status of the Menu Attributes fieldset using this method.

escoles’s picture

See the forms api documentation for how to address nested fieldsets. You can look at a field inside the fieldset you're targeting to get an idea of what the right way to address it is. E.g., to address the 'collapsed' setting for the menu_attributes fieldset, you would use:

$form['menu']['options']['attributes']['#collapsed']

Note that the names of the child arrays aren't obvious.