PrivateAccess.php in Field Permissions 8
File
src/Plugin/FieldPermissionType/PrivateAccess.php
View source
<?php
namespace Drupal\field_permissions\Plugin\FieldPermissionType;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\user\UserInterface;
class PrivateAccess extends Base {
public function hasFieldAccess($operation, EntityInterface $entity, AccountInterface $account) {
if ($account
->hasPermission('access private fields')) {
return TRUE;
}
if ($entity
->isNew()) {
return TRUE;
}
if ($entity instanceof UserInterface) {
return $entity
->id() == $account
->id();
}
elseif ($entity instanceof EntityOwnerInterface) {
return $entity
->getOwnerId() == $account
->id();
}
return TRUE;
}
public function hasFieldViewAccessForEveryEntity(AccountInterface $account) {
return $account
->hasPermission('access private fields');
}
}