views:

29

answers:

2

hi,

I want to customize my Drupal back-end forms.

I'm using template.php file.. i.e.

  $form['menu']['#collapsed'] = true;
  $form['author']['#collapsed'] = true;
  $form['buttons']['#weight']  = 100;

But I was wondering from where the section names (menu, author, buttons), come from. (They are not id or classes in html code, so I guess there is an index with all names stored somewhere.

Where can I get the complete list of section names ?

For example, what are the names for revision and publishing sections ? 'revision', 'publish', 'publishing' don't work.

thanks

A: 

I don't think there actually is a naming system with forms like that. The names is most likely the same used when defining the form, which could be anything really. Drupal core might be consistent, but if you want to add contrib modules, you can't be sure of anything.

googletorp
I'm actually trying to understand where can I read the names, for example to change the weight of "revision" section.. I can only try different names, but it is not very efficient method.
Patrick
You can use the devel module's `dpm` or just plain old `print_r` to inspect a variable.
googletorp
cool thanks, I was missing print_r
Patrick
one more thing, is there any way to make the printed php more readable ? Is actually difficult to understand the array structure in the plain text file.
Patrick
@Patrick install the devel module and use `dpm($form)` instead
googletorp
+2  A: 

If I am not mistaken, you want to see structure of some forms. Each form in drupal has an Id. First, you need to know the form_id. You can do this with a custom module and implementation of hook_form_alter:

function mymodule_form_alter(&$form, $form_state, $form_id) {
    drupal_set_message($form_id);
}

When you have found the Id, alter the snippet to prints out the form structure:

function mymodule_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'a_form_id') {
        drupal_set_message(print_r('<pre>'. $form .'</pre>', true));
        // If you have installed Devel module, following line is much more readable:
        // dpm($form);
    }
}

Now when you go to the page containing the form, you see it's structure.Each form element is represented as an array, for example, a text field can be like this:

$form['name'] = array(
    '#type' => 'textarea',
    '#title' => t('Username')
);

Look for Form API in Drupal website for more info.

farzan

related questions