You are here

protected function SocialTagsBlock::blockAccess in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  2. 8 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  3. 8.2 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  4. 8.3 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  5. 8.4 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  6. 8.6 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  7. 8.7 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  8. 8.8 modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  9. 10.3.x modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  10. 10.0.x modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  11. 10.1.x modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()
  12. 10.2.x modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php \Drupal\social_tagging\Plugin\Block\SocialTagsBlock::blockAccess()

Logic to display the block in the sidebar.

Overrides BlockPluginTrait::blockAccess

File

modules/social_features/social_tagging/src/Plugin/Block/SocialTagsBlock.php, line 77

Class

SocialTagsBlock
Provides a 'SocialTags' block.

Namespace

Drupal\social_tagging\Plugin\Block

Code

protected function blockAccess(AccountInterface $account) {

  // If tagging is off, deny access always.
  if (!$this->tagService
    ->active()) {
    return AccessResult::forbidden();
  }
  $route_name = $this->routeMatch
    ->getRouteName();
  if ($route_name == 'entity.node.canonical') {
    $node = $this->routeMatch
      ->getParameter('node');
    if ($node instanceof Node) {
      if ($node
        ->hasField('social_tagging')) {
        if (!empty($node
          ->get('social_tagging')
          ->getValue())) {

          // We only show the block if the field contains values.
          return AccessResult::allowed();
        }
      }
    }
  }
  return AccessResult::forbidden();
}