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.
\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.
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.
\Drupal\Core\Entity\EntityAccessController::access()
\Drupal\block\BlockAccessController::checkAccess()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
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;
}
}