2

I'd like to hide/remove theme block tabs for certain roles in drupal. For example Administrator can edit both theme blocks, but other roles can edit only blocks that are available in their current theme.

Picture: enter image description here

As you can see on picture, I'd like to hide SEVEN from other roles that are not Administrator ? Any ideas.

Thanks!

2
function HOOK_menu_alter(&$items) {
  global $user;
  if(in_array('administrator', $user->roles) == FALSE && in_array('admin/structure/block/list/seven', array_keys($items)) == TRUE) {
    // This allows the path to still be registered but not displayed
    $items['admin/structure/block/list/seven']['type'] = MENU_CALLBACK;
  }
}
  • Nice. In case I decide not to change template file, is there a module alternative ? Thanks! – Michael Feb 17 '16 at 19:29
  • You could make a simple module and put that code in the module file. You would just replace HOOK with the module name. – Chad Payne Feb 17 '16 at 21:25
1

Your answer led me to the correct solution.

Correct answer is this :

function remove_tab_for_non_admins_menu_alter(&$items) {
  if(isset($items['admin/structure/block/list/seven'])) {
    $items['admin/structure/block/list/seven']['access callback'] = 'remove_tab_for_non_admin_check_access';
  }
}

function remove_tab_for_non_admin_check_access() {
  global $user;
  return in_array('administrator', $user->roles);
}

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.