How can I permanently expand the "File attachment" fieldset?

jeeves - February 27, 2008 - 06:05

By default, the "File attachments" fieldset loads up collapsed when editing or creating a node. This creates a problem for site users because they don't notice where they are supposed to upload files.

Is there anyway I can just have the File attachment fieldset just load up expanded, so it's easy to spot?

Override theme_fieldset

CrookedNumber - February 27, 2008 - 22:26

It's not trivial, but the most straightforward way would be to include in your theme an override of the theme_fieldset function

http://api.drupal.org/api/function/theme_fieldset

But I might be over-thinking this one.

[You could also add a touch of jQuery to the page, so that the fieldset opens at load.]

Something like (this is UNTESTED)

<?php
function YOUR_THEME_NAME_fieldset($element) {
  if (
$element['#collapsible']) {
   
drupal_add_js('misc/collapse.js');

    if (!isset(
$element['#attributes']['class'])) {
     
$element['#attributes']['class'] = '';
    }

   
$element['#attributes']['class'] .= ' collapsible';
    if (
$element['#collapsed'] && $element['#title']!='File attachments') {
    
$element['#attributes']['class'] .= ' collapsed';
    }
  }

  return
'<fieldset' . drupal_attributes($element['#attributes']) .'>' . ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . ($element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . $element['#children'] . $element['#value'] . "</fieldset>\n";
}
?>

Looks good

CrookedNumber - February 27, 2008 - 22:28

quick follow up. I just tested this on a (local) drupal test site. Seems to work.

Anyone else, feel free to chime in if there's an even easier solution.

What about

rgeorgy - May 19, 2008 - 09:57

What about this:

$form['attachments']['#collapsed'] = false;

Where are you placing that

CrookedNumber - May 19, 2008 - 13:53

Where are you placing that line of code?

In any hook_form_alter

rgeorgy - May 21, 2008 - 11:00

In any hook_form_alter implementation at your modules, you could alter whatever form you want (i.e. [nodetype]_node_form). You'll be altering the behaviuor of attachment fieldset to be always expanded (in other words never collapsed) by this code snippet:-

function [module-name]_form_alter($form_id, &$form) {
if($form_id == [node-type]_node_form') {
    $form['attachments']['#collapsed'] = false;
  }
}

I hope that helps

True

CrookedNumber - May 23, 2008 - 15:07

Yeah, this looks good to me. I was assuming that Jeeves wanted every node form to always behave this way and thus wanted to do this on the theme level, rather than build a module just to do that. But re-reading his first post, that's not entirely clear.

Jeeves? Any update on this?

 
 

Drupal is a registered trademark of Dries Buytaert.