By trogie on
Hello,
I'm trying to overwrite the upload.module default form settings in a custom content type module. I don't want the 'attachments fieldset' to be collapsed when creating a new node of my content type.
So I have:
function mynode_form_alter( $form_id, &$form) {
$form['attachments']['#collapsed'] = FALSE;
$form['attachments']['#collapsible'] = FALSE;
}
Offcourse there should be some more form_id and type checking but I'll add these later.
The problem is that the upload fieldset stays collapsed. When I dump the $form object I don't even see the 'attachements' subarray of $form! Is this because my hook_form_alter function gets executed before the upload_form_alter (upload.module v1.148 line 341) function of the upload.module?
What can I do to not have the fieldset collapsed?
Trogie
Comments
order of form_alter function execution
OK.
I added a little drupal_set_message to the form_alter of my module and the upload.module and the upload module message comes on the second line of the drupal message...
Seems indead that there's a little race condition...
What can I do to changes the file attachments fieldset anyway?
Thanks,
Trogie
Not a race
It's not a race condition, it's a strict queuing process, and you're just coming in a bit too soon.
Each module gets a chance to 'form_alter' the form, one at a time. If your turn comes BEFORE the upload.module has done its thing, you can hardly manipulate its bits yet.
Good news is that's totally taken care of. Set your module weight to > the upload module weight. You'll find it in the system table of the database.
This is something that's usually done on module.install like so:
There's also a callback in the FAPI for '#after_build' or something, but I think that's black magic.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Great!
OK thanks dman!
This did it! I learn every day.
Trogie
What about cck videofield?
I'm having the same type of problem with cck videofield type.
I'm setting a bunch of default values on the content forms based on the content type with form_alter. After submitting, all the defaults
are put int but the video file is never uploaded.
I tried the fix above but it does not have the same result as working with the upload module.
Any thoughts?
dont use onsubmit form event
I replaced my onsubmit form event and my problems went away. Wasn't playing nice with what looks like two submits going on for media fields.