You are here

protected function DashboardAccessControlHandler::checkAccess in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/DashboardAccessControlHandler.php \Drupal\dashboards\Entity\DashboardAccessControlHandler::checkAccess()

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkAccess

File

src/Entity/DashboardAccessControlHandler.php, line 18

Class

DashboardAccessControlHandler
DashboardAccessControlHandler class.

Namespace

Drupal\dashboards\Entity

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation == 'delete' && $entity
    ->isNew()) {
    return AccessResult::forbidden()
      ->addCacheableDependency($entity);
  }
  if ($operation == 'view') {
    return AccessResult::allowedIfHasPermission($account, 'can view ' . $entity
      ->id() . ' dashboard')
      ->orIf(AccessResult::allowedIfHasPermission($account, $this->entityType
      ->getAdminPermission()));
  }
  if ($operation == 'edit') {
    return AccessResult::allowedIfHasPermission($account, $this->entityType
      ->getAdminPermission())
      ->orIf(AccessResult::allowedIfHasPermission($account, 'can override ' . $entity
      ->id() . ' dashboard'));
  }
  if ($this->entityType
    ->getAdminPermission()) {
    return AccessResult::allowedIfHasPermission($account, $this->entityType
      ->getAdminPermission());
  }
  else {
    return AccessResult::neutral();
  }
}