1

When editing the setting of a block you can specify Themes and Regions where the block is going to be shown.

I need to hide some Region and a Theme for a given role? Can I do this?

I tried with http://drupal.org/project/block_access but is not useful for this.

0

You can do it with dirty fix:

Add body class for required role(s), and hide with css conditions.

| improve this answer | |
  • I already thought of doing in that way. How do I add the role as class in the body? – chefnelone Apr 16 '13 at 14:43
  • themplate_preprocess_page(&$vars) – Oleg Sherbakov Apr 19 '13 at 10:02
2

it's a bit late but for the people in the same situation :

function MODULE_form_alter(&$form, &$form_state, $form_id){
    global $user;
    if($form_id == 'block_admin_configure'){
        if(in_array('your_role_name',$user->roles)){
            hide($form['regions']);
            hide($form['visibility']); //for the visibility region
            hide($form['visibility_title']); //for the visibility region
        }
    }
}
| improve this answer | |
2

To change the Region & Theme output, first locate the settings in the Block Module block.admin.inc file on line 297. Adjust region and theme by adding logic (like an if statement for user permissions).

You can use the following snippet as a starting point or start from scratch if you are comfortable writing it from the ground-up.

Include the following snippet in a hook_form_alter() function.

$theme_default = variable_get('theme_default', 'bartik');
  $admin_theme = variable_get('admin_theme');
  foreach (list_themes() as $key => $theme) {
    // Only display enabled themes
    if ($theme->status) {
      $region = db_query("SELECT region FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(
        ':module' => $block->module,
        ':delta' => $block->delta,
        ':theme' => $key,
      ))->fetchField();

      // Use a meaningful title for the main site theme and administrative
      // theme.
      $theme_title = $theme->info['name'];
      if ($key == $theme_default) {
        $theme_title = t('!theme (default theme)', array('!theme' => $theme_title));
      }
      elseif ($admin_theme && $key == $admin_theme) {
        $theme_title = t('!theme (administration theme)', array('!theme' => $theme_title));
      }
      $form['visibility']['regions'][$key] = array(
        '#type' => 'select',
        '#title' => $theme_title,
        '#default_value' => !empty($region) && $region != -1 ? $region : NULL,
        '#empty_value' => BLOCK_REGION_NONE,
        '#options' => system_region_list($key, REGIONS_VISIBLE),
        '#weight' => ($key == $theme_default ? 9 : 10),
      );
    }
  }  
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.