protected function LocalTaskItemAccessController::checkAccess

File

translators/tmgmt_local/src/Entity/Controller/LocalTaskItemAccessController.php, line 20

Class

LocalTaskItemAccessController
Access control handler for the task item entity.

Namespace

Drupal\tmgmt_local\Entity\Controller

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation == 'view' || $operation == 'update') {
    if ($account
      ->hasPermission('administer tmgmt') || $account
      ->hasPermission('administer translation tasks')) {

      // Administrators can do everything.
      return AccessResult::allowed()
        ->cachePerPermissions();
    }
    return AccessResult::allowedIf($entity
      ->getTask()->tuid->target_id == $account
      ->id() && $account
      ->hasPermission('provide translation services'));
  }
  return $entity
    ->getTask()
    ->access($operation, $account, TRUE);
}