function 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.");
}