X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity%2Fsrc%2FUncacheableEntityAccessControlHandler.php;fp=web%2Fmodules%2Fcontrib%2Fentity%2Fsrc%2FUncacheableEntityAccessControlHandler.php;h=a53724bedffe178a211b2ed81bd3d795d40d35b6;hp=0000000000000000000000000000000000000000;hb=f3baf763d342a5f82576890e2a8111a5aaf139dc;hpb=059867c3f96750652c80f39e44c442a58c2549ee diff --git a/web/modules/contrib/entity/src/UncacheableEntityAccessControlHandler.php b/web/modules/contrib/entity/src/UncacheableEntityAccessControlHandler.php new file mode 100644 index 000000000..a53724bed --- /dev/null +++ b/web/modules/contrib/entity/src/UncacheableEntityAccessControlHandler.php @@ -0,0 +1,54 @@ +hasHandlerClass('permission_provider') || !is_a($entity_type->getHandlerClass('permission_provider'), UncacheableEntityPermissionProvider::class, TRUE)) { + throw new \Exception('\Drupal\entity\UncacheableEntityAccessControlHandler requires the \Drupal\entity\UncacheableEntityPermissionProvider permission provider.'); + } + } + + /** + * {@inheritdoc} + */ + protected function checkEntityOwnerPermissions(EntityInterface $entity, $operation, AccountInterface $account) { + /** @var \Drupal\user\EntityOwnerInterface $entity */ + if ($operation === 'view' && $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 = parent::checkEntityOwnerPermissions($entity, $operation, $account); + } + + return $result; + } + +}