protected function JobAccessControlHandler::checkAccess in Translation Management Tool 8
Performs access checks.
This method is supposed to be overwritten by extending classes that do their own custom access checking.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.
string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides EntityAccessControlHandler::checkAccess
1 method overrides JobAccessControlHandler::checkAccess()
- JobItemAccessControlHandler::checkAccess in src/
Entity/ Controller/ JobItemAccessControlHandler.php - Performs access checks.
File
- src/
Entity/ Controller/ JobAccessControlHandler.php, line 20
Class
- JobAccessControlHandler
- Access control handler for the job entity.
Namespace
Drupal\tmgmt\Entity\ControllerCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\tmgmt\JobInterface $entity */
if ($account
->hasPermission('administer tmgmt')) {
// Administrators can do everything.
return AccessResult::allowed()
->cachePerPermissions();
}
switch ($operation) {
case 'view':
case 'update':
return AccessResult::allowedIfHasPermission($account, 'create translation jobs')
->orIf(AccessResult::allowedIfHasPermission($account, 'accept translation jobs'));
break;
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete translation jobs')
->andIf(AccessResult::allowedIf(!$entity
->isActive()))
->addCacheableDependency($entity);
break;
// Custom operations.
case 'submit':
return AccessResult::allowedIfHasPermission($account, 'submit translation jobs');
break;
case 'accept':
return AccessResult::allowedIfHasPermission($account, 'accept translation jobs');
break;
case 'abort':
case 'resubmit':
return AccessResult::allowedIfHasPermission($account, 'submit translation jobs');
break;
}
}