function hook_block_access

Control access to a block instance.

Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a block instance.

Parameters

\Drupal\block\Plugin\Core\Entity\Block $block: The block instance.

string $operation: The operation to be performed, e.g., 'view', 'create', 'delete', 'update'.

\Drupal\user\Plugin\Core\Entity\User $account: The user object to perform the access check operation on.

string $langcode: The language code to perform the access check operation on.

Return value

bool|NULL FALSE denies access. TRUE allows access unless another module returns FALSE. If all modules return NULL, then default access rules from \Drupal\block\BlockAccessController::checkAccess() are used.

See also

\Drupal\Core\Entity\EntityAccessController::access()

\Drupal\block\BlockAccessController::checkAccess()

Related topics

2 functions implement hook_block_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

node_block_access in drupal/core/modules/node/node.module
Implements hook_block_access().
overlay_block_access in drupal/core/modules/overlay/overlay.module
Implements hook_block_access().

File

drupal/core/modules/block/block.api.php, line 94
Hooks provided by the Block module.

Code

function hook_block_access(\Drupal\block\Plugin\Core\Entity\Block $block, $operation, \Drupal\user\Plugin\Core\Entity\User $account, $langcode) {

  // Example code that would prevent displaying the 'Powered by Drupal' block in
  // a region different than the footer.
  if ($operation == 'view' && $block
    ->get('plugin') == 'system_powered_by_block' && $block
    ->get('region') != 'footer') {
    return FALSE;
  }
}