Hello again,

Using the module in multiple-attachments mode, I would like the File attachments box to be expanded by default when a user adds a new comment. Not sure how to make that happen, so I thought I'd ask while I try to figure it out.

Thanks
jrd

CommentFileSizeAuthor
#8 expand_file_attachments.zip1.19 KBscarer

Comments

heine’s picture

You can write a module that implements a form_alter hook, and sets the collapsed property of the attachments field to false:

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

As it has to run after CU, give it a weight of 11 in the system table.

jrdixey’s picture

Hi Heine,

That worked. Cheers!

Question: Is the little module I wrote based on your advice worth contributing? Might save someone some time if they don't know PHP. I'm sure it could use a lot more work (like making it optional based on the content type), which I don't know how to do yet, but I'm thinking if I were to contribute it, someone else might want to help expand on it. What do you think?

jrd

heine’s picture

Status: Active » Fixed

Not really, and certainly not as an extra module vs. a patch against CU. The current behaviour is sane and applies to most situations.

jrdixey’s picture

Title: How to make File attachments box expanded by default? » File attachments area of the comment form expanded by default (optional)
Category: support » feature
Priority: Normal » Minor

Thanks for the feedback -- I suspected as much. I'm just learning about how all this comes together so I appreciate your assistance.

I'm changing this to a minor feature request, so when/if there's a new maintainer they can pick it up if they're interested.

jrd

Status: Fixed » Closed (fixed)

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

RikiB’s picture

I dont know php extremely well, could you give a little tutorial on how you did it? I would love to be able to do this, Im using the Drupal 6 version btw. Is there a way I can just patch the module itself?

jrdixey’s picture

Hi Riki,

I would strongly advise you not to patch the module itself - you would only have to patch it again after the next module upgrade. I'll zip up the little module I wrote and drop it here as an attachment. It works in D6. That said, it really is only one line of code, so a module is overkill for this. I've been told I should have done it differently (see above) but it's working, so I'm keeping it for now. :)

Cheers
Jennifer

scarer’s picture

StatusFileSize
new1.19 KB

here's a working little module if you need it. it's for drupal 6 :)
cheers,

sarah

volocuga’s picture

It seems the latest release has attachment form expanded by default. I'd like to collapse it

I created a module that contains the following:


function mymodule_form_alter(&$form, $form_state, $form_id) {

      if ($form_id == 'comment_form') {	  
      $form['attachments']['#collapsed'] = TRUE;
     }
	 	
}

I can change everything, for example using

$form['attachments']['#description'] = 'Custom description';

I can change a text inside the fieldset, BUT CAN NOT collapse the fieldset.

What am I doing wrong?

Thanks!

RikiB’s picture

Version: 5.x-0.1 » 6.x-1.0-alpha5
Priority: Minor » Normal
Status: Closed (fixed) » Active

Ive been searching and have tried everything but cant have "File attachments" expanded by default on comments. Is there any way to do this?

geerlingguy’s picture

Version: 6.x-1.0-alpha5 » 6.x-1.x-dev

@volocuga - you'll need to manually make sure your custom module's 'weight' in the system table (your database) is 'heavier' than the comment_upload module; that way your form alter will take precedence. I think this setting should be optional—I'd rather not have the file attachments form expanded by default, because I rarely need to use the comment upload form, but I'd still like it there...

So, the steps to fix this for your site:

1. Put the following into your site's custom.module (If your module is named something_else.module, replace 'custom' with 'something_else'):

/**
 * Implementation of hook_form_alter().
 */
function custom_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'comment-form') {
    $form['attachments']['#collapsed'] = TRUE;
  }
}

2. In your {system} table (in your site's database), make sure the 'weight' value for your custom module is higher (a greater integer) than the comment_upload module (for example, if comment_upload's weight is 0, you can have your module's 'weight' be 1 or more, and that will take care of it).

That way, you can override the default behavior.

xaa’s picture

hello,
thanks geerlingguy. it works fine !

Could you tell me why if I try to add the function on the comment_upload module directly it doesn't work ??