In Drupal 5.1, when creating a node type junk, I would like the Author and Attachments blocks to be expanded (i.e. ['#collapsed'] = FALSE;)
Based on searching around drupal.org, I decided to create a module to achieve this. Following is my code. It does not seem to work, the attachments and author blocks are still collapsed. Can you help? Any suggestions so I can learn how to debug this myself? I do have the devel module installed now.
<?php // $Id:
/** * @file * My module to modify forms. * * I create a module to modify forms to my liking. */
/** * Implementation */
function myformalter_form_alter($form_id, &$form) { if ($form_id == 'edit-junk-node-form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
-- Sincerely, John Thomas
Start with this .. change:
function myformalter_form_alter($form_id, &$form) { if ($form_id == 'edit-junk-node-form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
to:
function myformalter_form_alter($form_id, &$form) { print $form_id . "<br>"; print "<pre>"; print_r($form); print "</pre>";
if ($form_id == 'edit-junk-node-form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
When you go to the submission page, it wil spit out the form id. Make sure this matches "edit-junk-node-form" (I suspect it doesn't, form ids don't usually start with 'edit').
If it does match, check the rest of the output and make sure 'attachments' and 'author' are correct array indexes to be targeting.
William.
On 7/18/07, John Thomas drupal.org-2007@jt-socal.com wrote:
In Drupal 5.1, when creating a node type junk, I would like the Author and Attachments blocks to be expanded (i.e. ['#collapsed'] = FALSE;)
Based on searching around drupal.org, I decided to create a module to achieve this. Following is my code. It does not seem to work, the attachments and author blocks are still collapsed. Can you help? Any suggestions so I can learn how to debug this myself? I do have the devel module installed now.
<?php // $Id:
/**
- @file
- My module to modify forms.
- I create a module to modify forms to my liking.
*/
/**
- Implementation
*/
function myformalter_form_alter($form_id, &$form) { if ($form_id == 'edit-junk-node-form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
-- Sincerely, John Thomas
Sincerely, John Thomas -- [ Drupal support list | http://lists.drupal.org/ ]
William, thank you for your time. You gave me a nice step up the learning curve.
For those of you following along at home, here is the module (perhaps I will create a full blown module that will allow admins to change the default expand/collapse for each section in each node type (that sounds a bit intimidating still)).
In the meantime, create two files, put them in a new subdirectory under the appropriate modules directory (e.g. myformalter)
First file: myformalter.module <?php // $Id:
/** * @file * Module to modify form to expand author and attachments sections */
/** * Implementation */
function myformalter_form_alter($form_id, &$form) { //enable the following to get a view of all the variables //print $form_id . "<br>"; //print "<pre>"; print_r($form); print "</pre>"; if ($form_id == 'nameofyournode_node_form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
Second File: myformalter.info ; $Id$ name = MYFormAlter description = Modifies form specified as specified in txt file package = 00-my version = "1.0"
Start with this .. change:
function myformalter_form_alter($form _id, &$form) { if ($form_id == 'edit-junk-node-form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
to:
function myformalter_form_alter($form _id, &$form) { print $form_id . "<br>"; print "<pre>"; print_r($form); print "</pre>";
if ($form_id == 'edit-junk-node-form') { $form['attachments']['#collapsed'] = FALSE; $form['author']['#collapsed'] = FALSE; } }
When you go to the submission page, it wil spit out the form id. Make sure this matches "edit-junk-node-form" (I suspect it doesn't, form ids don't usually start with 'edit').
If it does match, check the rest of the output and make sure 'attachments' and 'author' are correct array indexes to be targeting.
William.