Same name and namespace in other branches
  1. 7.x-3.x plugins/QuickBlockContent.inc \QuickBlockContent::accessBlock()

Checks if the current user can access a block.

1 call to QuickBlockContent::accessBlock()
QuickBlockContent::render in src/Plugin/QuickContent/QuickBlockContent.php
Renders the content.

File

src/Plugin/QuickContent/QuickBlockContent.php, line 135

Class

QuickBlockContent
Class for tab content of type "block" - this is for rendering a block as tab content. @QuicktabFormat{ id = "quickblockcontent

Namespace

Drupal\quicktabs\Plugin\QuickContent

Code

private function accessBlock($module, $delta) {
    // Get current user's rids.
    global $user;
    $rids = array_keys($user->roles);
    // Get authorized rids.
    $authorized_rids = db_select('block_role', 'br')->fields('br', array(
        'rid',
    ))
        ->condition('module', $module, '=')
        ->condition('delta', $delta, '=')
        ->execute()
        ->fetchCol('rid');
    // Return whether the user can access the block:
    // - Either all roles have access - no record in {block_role}
    // - Or only specific roles have access - in which case rids should match.
    return count($authorized_rids) == 0 || count(array_intersect($authorized_rids, $rids)) != 0;
}