function ip_ban_block_access in IP Ban 8
Implements hook_block_access($block).
Todo: need to move the ip_ban_determine_action to a new location so it's not called once for each block.
File
- ./
ip_ban.module, line 40 - Module can "ban" or set site to "read only" by country or IP address.
Code
function ip_ban_block_access(Block $block) {
// Take no action if the user has the "Bypass ban" permission.
if (\Drupal::currentUser()
->hasPermission('ignore ip_ban')) {
return;
}
// $subscriber = new IpBanSubscriber();
// $banvalue = $subscriber->getBanValue();
// kint($banvalue);
$disabled_blocks = \Drupal::config('ip_ban.settings')
->get('ip_ban_disabled_blocks');
$disabled_block_list = array();
if (!empty($disabled_blocks)) {
$disabled_block_array = explode(PHP_EOL, $disabled_blocks);
foreach ($disabled_block_array as $disabled_block) {
$disabled_block_list[] = preg_replace('/\\s+/', '', $disabled_block);
}
}
if (!empty($disabled_block_list)) {
if (in_array($block
->id(), $disabled_block_list)) {
//return AccessResult::forbidden();
unset($block);
}
}
}