You are here

function block_access_check_perms in Block Access 6.2

Same name and namespace in other branches
  1. 6 block_access.module \block_access_check_perms()
  2. 7 block_access.module \block_access_check_perms()
1 call to block_access_check_perms()
block_access_form_alter in ./block_access.module

File

./block_access.module, line 227

Code

function block_access_check_perms(&$form, $key, $block) {
  $module = $block['module']['#value'];
  $delta = $block['delta']['#value'];

  // Remove the block completely if it's not allowed to be viewed
  if (!block_access_can_view($module, $delta)) {
    unset($form[$key]);
  }
  else {

    // Remove the delete link if the user can't delete this block
    if (!block_access_can_delete($module, $delta)) {
      unset($form[$key]['delete']);
    }

    // Remove the configure link if the user can't configure this block
    if (!block_access_can_config($module, $delta)) {
      unset($form[$key]['configure']);
    }

    // if a block is in BLOCK_REGION_NONE it is effectively disabled
    if ($block['region']['#default_value'] == BLOCK_REGION_NONE) {

      // Disable the region selection and weight if the user can't enable the block
      if (!block_access_can_enable($module, $delta)) {
        $form[$key]['region']['#disabled'] = TRUE;
        $form[$key]['weight']['#disabled'] = TRUE;
      }
    }
    else {

      // Unset the regions in the region selection if the user can't move the block
      if (!block_access_can_move($module, $delta)) {
        foreach ($form[$key]['region']['#options'] as $option => $value) {
          if ($option != BLOCK_REGION_NONE && $option != $form[$key]['region']['#default_value']) {
            unset($form[$key]['region']['#options'][$option]);
          }
        }
      }

      // Remove the <none> option from the select list if the user can't disable the block
      if (!block_access_can_disable($module, $delta)) {
        unset($form[$key]['region']['#options'][BLOCK_REGION_NONE]);
      }
    }
  }
}