function EntityView::access

Same name in other branches
  1. 4.0.x src/Plugin/Block/EntityView.php \Drupal\ctools\Plugin\Block\EntityView::access()

Overrides BlockPluginTrait::access

File

src/Plugin/Block/EntityView.php, line 121

Class

EntityView
Provides a block to view a specific entity.

Namespace

Drupal\ctools\Plugin\Block

Code

public function access(AccountInterface $account, $return_as_object = FALSE) {
    // Check the parent's access.
    $parent_access = parent::access($account, TRUE);
    if (!$parent_access->isAllowed()) {
        return $return_as_object ? $parent_access : $parent_access->isAllowed();
    }
    
    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this->getContextValue('entity');
    if ($entity) {
        if ($this->getAccessRecursion($entity, $this->getConfiguration())) {
            return $return_as_object ? new AccessResultForbidden() : FALSE;
        }
        return $entity->access('view', $account, $return_as_object);
    }
    return new AccessResultForbidden("No Entity Found.");
}