views:

157

answers:

3

Hiya,

Can anyone advise me on customising the Add Block form? (/admin/build/block/add)

I want to hide the "User specific visibility settings" and "Role specific visibility settings" from users. This is what i've got so far, but obviously it's not right and I can't figure out what the array is. Anyone got the experience on this?

function theme_add_block_form($form) {
    $form['roles']['#prefix'] = '<div class="hidden">';
    $form['roles']['#suffix'] = '</div>';
    return drupal_render($form);
}

Thanks, H

EDIT - perhaps I wasn't clear - I'm comforable using the various form hooks from the API, but my problem in this case is that I can't identify the array elements to use in my function. The devel module doesn't seem to act on the blocks page, and the themer popup block thing is less than clear.

A: 

http://api.drupal.org/api/function/hook_form_alter/6

Nikit
yeah that's one option for performing the theming, but I need some help actually identifying the elements of the array to put into the function. I can't identify them using the Devel module as it doesn't appear to act on that page.
hfidgen
dpm($form) in hook_form_alter if you have devel (print_r if not), you'll see all internal datas for form. Add there you own form elements, and add own validate and submit calls. Learn this more helpful: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6
Nikit
Tried that already - sorry should have left that in the code example :)
hfidgen
+3  A: 

In modules/block/block.admin.inc, function block_admin_configure:

$form['user_vis_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('User specific visibility settings'),
    '#collapsible' => TRUE,
  );

(...)

$form['role_vis_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Role specific visibility settings'),
    '#collapsible' => TRUE,
  );

Just try to hide $form['user_vis_settings'] and $form['role_vis_settings'].

EDIT:

Don't touch modules/block/block.admin.inc!! (I only was pointing where I found the form fields' names ). Hide the fields in your theme_add_block_form. Instead of wrapping the fields inside a div, you can write $form['user_vis_settings']['#access'] = false;

dusan
don't touch core code! use hooks...
Nikit
I didn't intend to say that! I'll clarify my answer.
dusan
Nice one, cheers Dusan, didn't think of looking in there. And yeah don't worry I wouldn't have made my edits there, It should be clear from my post that I was creating a theme template.php function anyway. No need for the negative vote down!
hfidgen
points returned, never show for newbies hacking drupal code :)
Nikit
Thanks Nikit, I'll write my answers more carefully. =)
dusan
A: 

This is the way to go. Using the http://api.drupal.org/api/function/hook_form_alter/6 as say in an other answer. You need to write this code in a costum module.

<?php   
 function module_name_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'block_admin_configure') {
       $form['user_vis_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('User specific visibility settings'),
        '#collapsible' => TRUE,
        '#access' = FALSE,
       );
       $form['role_vis_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Role specific visibility settings'),
        '#collapsible' => TRUE,
        '#access' = FALSE,
       );
      }
    }
gagarine