Posted by Rosamunda on May 4, 2009 at 10:02pm
Hello there!
I would like to expand by default all "add attachment" links in certain nodetypes only.
My guess is that it can be done from template.tpl.php. I´ve searched around and didn´t find exactly what I was looking for, because usually all posts are reffering to specific links created by specific contrib modules.
I want to expand the default attachment link. Let it still be collapsible, but expanded by default on all nodes of type A, B and F only.
Hope you can help me out!
Rosamunda
Comments
hook_form_alter
You need to create a new module and use hook_form_alter to modify the form.
<?phpfunction YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'page_node_form' || $form_id == 'othercontenttype_node_form') {
$form['attachments']['#collapsed'] = FALSE;
}
}
?>
--Zivtech--
template.php
You can do this from template.php, too. You need to declare a function to theme the form with hook_theme, and then include Jody's code in that function, like so:
<?php
function YOURTHEME_theme($existing, $type, $theme, $path) {
return array(
'YOUR_FORM_NAME' => array(
'arguments' => array('form' => NULL),
),
);
}
function YOURTHEME_preprocess_YOUR_FORM_NAME(&$vars) {
$vars['form']['attachments']['#collapsed'] = FALSE;
}
?>
(Note the & in &$vars. Without it, the changes to $vars will be ignored by your template.)
For more on using hook_theme to theme forms, see this tutorial on Trellon or this tutorial on 11 heavens about theming the user register form.
Oh! I didn´t see your reply
Oh! I didn´t see your reply when posted my last message. Sorry :)
Thanks you too grobemo! Personally I prefer to do this from the template.tpl. I think it´s easier than crating a whole new module for just a tiny hook.
Thanks!
Rosamunda
Rosamunda
Buenos Aires | Argentina
You just saved me Jody,
You just saved me Jody, thanks!!!!!!!!
Works like a charm!
Rosamunda
Rosamunda
Buenos Aires | Argentina
Altering an already altered form
I've tried this and it didn't work, because I tried to uncollapsed a fieldset already modified by another module (Taxonomy Super Select). A solution I found is detailed here: http://drupal.org/node/549562#comment-1960232.