protected function LinkCheckerLinkAccessControlHandler::checkParentEntityAccess in Link checker 8
Helper function for access checking.
2 calls to LinkCheckerLinkAccessControlHandler::checkParentEntityAccess()
- LinkCheckerLinkAccessControlHandler::checkAccess in src/
LinkCheckerLinkAccessControlHandler.php - Performs access checks.
- LinkCheckerLinkAccessControlHandler::checkFieldAccess in src/
LinkCheckerLinkAccessControlHandler.php - Default field access as determined by this access control handler.
File
- src/
LinkCheckerLinkAccessControlHandler.php, line 67
Class
- LinkCheckerLinkAccessControlHandler
- Defines the access control handler for the linkchecker link entity type.
Namespace
Drupal\linkcheckerCode
protected function checkParentEntityAccess(LinkCheckerLinkInterface $entity, $operation, AccountInterface $account) {
$parentEntity = $entity
->getParentEntity();
// If parent not exists - forbidden.
if (!isset($parentEntity)) {
return AccessResult::forbidden()
->cachePerPermissions();
}
// If user does not have access to parent entity - forbidden.
if (!$parentEntity
->access($operation, $account)) {
return AccessResult::forbidden()
->addCacheableDependency($parentEntity)
->cachePerPermissions();
}
// If field where link was stored not exists anymore - forbidden.
if (!$parentEntity
->hasField($entity
->getParentEntityFieldName())) {
return AccessResult::forbidden()
->addCacheableDependency($parentEntity)
->cachePerPermissions();
}
// If user does not have access to field where link is stored - forbidden.
$parentEntityField = $parentEntity
->get($entity
->getParentEntityFieldName());
if (!$parentEntityField
->access($operation, $account)) {
return AccessResult::forbidden()
->addCacheableDependency($parentEntity)
->cachePerPermissions();
}
// Allowed in all other cases.
return AccessResult::allowed()
->addCacheableDependency($parentEntity)
->cachePerPermissions();
}