protected function OrganizationAccessControlHandler::checkOwn in Drupal PM (Project Management) 4.x
Test for given 'own' permission.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
string $operation: The entity operation that needs to be performed.
\Drupal\Core\Session\AccountInterface $account: The user account.
Return value
string|null The permission string indicating it's allowed.
1 call to OrganizationAccessControlHandler::checkOwn()
- OrganizationAccessControlHandler::checkAccess in modules/
pm_organization/ src/ OrganizationAccessControlHandler.php - Performs access checks.
File
- modules/
pm_organization/ src/ OrganizationAccessControlHandler.php, line 84
Class
- OrganizationAccessControlHandler
- Access controller for the Organization entity.
Namespace
Drupal\pm_organizationCode
protected function checkOwn(EntityInterface $entity, string $operation, AccountInterface $account) {
$status = $entity
->isPublished();
$uid = $entity
->getOwnerId();
$is_own = $account
->isAuthenticated() && $account
->id() == $uid;
if (!$is_own) {
return;
}
$bundle = $entity
->bundle();
$ops = [
'create' => '%bundle add own %bundle entities',
'view unpublished' => '%bundle view own unpublished %bundle entities',
'view' => '%bundle view own entities',
'update' => '%bundle edit own entities',
'delete' => '%bundle delete own entities',
];
$permission = strtr($ops[$operation], [
'%bundle' => $bundle,
]);
if ($operation === 'view unpublished') {
if (!$status && $account
->hasPermission($permission)) {
return $permission;
}
else {
return NULL;
}
}
if ($account
->hasPermission($permission)) {
return $permission;
}
return NULL;
}