X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fmodules%2Fcontrib%2Fentity%2Fsrc%2FEntityAccessControlHandler.php;fp=web%2Fmodules%2Fcontrib%2Fentity%2Fsrc%2FEntityAccessControlHandler.php;h=01f8fd6f59c522ac9aed8fc306d5d36e96eb3f0d;hb=f3baf763d342a5f82576890e2a8111a5aaf139dc;hp=0000000000000000000000000000000000000000;hpb=059867c3f96750652c80f39e44c442a58c2549ee;p=yaffs-website diff --git a/web/modules/contrib/entity/src/EntityAccessControlHandler.php b/web/modules/contrib/entity/src/EntityAccessControlHandler.php new file mode 100644 index 000000000..01f8fd6f5 --- /dev/null +++ b/web/modules/contrib/entity/src/EntityAccessControlHandler.php @@ -0,0 +1,60 @@ +hasHandlerClass('permission_provider') || !is_a($entity_type->getHandlerClass('permission_provider'), EntityPermissionProvider::class, TRUE)) { + throw new \Exception('\Drupal\entity\EntityAccessControlHandler requires the \Drupal\entity\EntityPermissionProvider permission provider.'); + } + } + + /** + * {@inheritdoc} + */ + protected function checkEntityOwnerPermissions(EntityInterface $entity, $operation, AccountInterface $account) { + /** @var \Drupal\user\EntityOwnerInterface $entity */ + if ($operation === 'view') { + if ($entity instanceof EntityPublishedInterface && !$entity->isPublished()) { + if ($account->id() != $entity->getOwnerId()) { + // There's no permission for viewing other user's unpublished entity. + return AccessResult::neutral()->cachePerUser(); + } + + $permissions = [ + "view own unpublished {$entity->getEntityTypeId()}", + ]; + $result = AccessResult::allowedIfHasPermissions($account, $permissions)->cachePerUser(); + } + else { + $result = AccessResult::allowedIfHasPermissions($account, [ + "view {$entity->getEntityTypeId()}", + "view {$entity->bundle()} {$entity->getEntityTypeId()}", + ], 'OR'); + } + } + else { + $result = parent::checkEntityOwnerPermissions($entity, $operation, $account); + } + + return $result; + } + +}