protected function BoardAccessControlHandler::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 BoardAccessControlHandler::checkOwn()
- BoardAccessControlHandler::checkAccess in modules/
pm_board/ src/ BoardAccessControlHandler.php - Performs access checks.
File
- modules/
pm_board/ src/ BoardAccessControlHandler.php, line 75
Class
- BoardAccessControlHandler
- Access controller for the Board entity.
Namespace
Drupal\pm_boardCode
protected function checkOwn(EntityInterface $entity, string $operation, AccountInterface $account) {
$uid = $entity
->getOwnerId();
$is_own = $account
->isAuthenticated() && $account
->id() == $uid;
if (!$is_own) {
return NULL;
}
$bundle = $entity
->bundle();
$ops = [
'create' => 'pm_board %bundle add own %bundle entities',
'view' => 'pm_board %bundle view own entities',
'update' => 'pm_board %bundle edit own entities',
'delete' => 'pm_board %bundle delete own entities',
];
$permission = strtr($ops[$operation], [
'%bundle' => $bundle,
]);
if ($account
->hasPermission($permission)) {
return $permission;
}
return NULL;
}