You are here

function block_access_check_perms in Block Access 7

Same name and namespace in other branches
  1. 6.2 block_access.module \block_access_check_perms()
  2. 6 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 372

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['blocks'][$key]);
  }
  else {

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

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

    // Disable the region selection and weight if the user can't move the block
    if (!block_access_can_move($module, $delta)) {
      $form['blocks'][$key]['region']['#access'] = FALSE;
      $form['blocks'][$key]['weight']['#access'] = FALSE;
    }
    else {

      // if a block is in BLOCK_REGION_NONE it is effectively disabled
      if ($form['blocks'][$key]['region']['#empty_value'] == BLOCK_REGION_NONE && !$form['blocks'][$key]['region']['#default_value']) {

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

      // Only allow regions the user can move into
      if (block_access_set_allowable_regions($module, $delta, $key, $form) === TRUE) {
        if ($form['blocks'][$key]['region']['#default_value']) {

          // 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['blocks'][$key]['region']['#empty_value']);
          }
        }
      }
    }
  }
}