protected function TimeTrackingAccessControlHandler::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 TimeTrackingAccessControlHandler::checkOwn()
- TimeTrackingAccessControlHandler::checkAccess in modules/
pm_timetracking/ src/ TimeTrackingAccessControlHandler.php - Performs access checks.
File
- modules/
pm_timetracking/ src/ TimeTrackingAccessControlHandler.php, line 75
Class
- TimeTrackingAccessControlHandler
- Access controller for the Time tracking entity.
Namespace
Drupal\pm_timetrackingCode
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_time_tracking %bundle add own %bundle entities',
'view' => 'pm_time_tracking %bundle view own entities',
'update' => 'pm_time_tracking %bundle edit own entities',
'delete' => 'pm_time_tracking %bundle delete own entities',
];
$permission = strtr($ops[$operation], [
'%bundle' => $bundle,
]);
if ($account
->hasPermission($permission)) {
return $permission;
}
return NULL;
}