class JobAccessControlHandler

Access control handler for the job entity.

Hierarchy

  • class \Drupal\tmgmt\Entity\Controller\JobAccessControlHandler extends \Drupal\Core\Entity\EntityAccessControlHandler

Expanded class hierarchy of JobAccessControlHandler

See also

\Drupal\tmgmt\Entity\Job.

File

src/Entity/Controller/JobAccessControlHandler.php, line 15

Namespace

Drupal\tmgmt\Entity\Controller
View source
class JobAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  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.

      // 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;
    }
    return AccessResult::neutral();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    return AccessResult::allowedIfHasPermission($account, 'create translation jobs')
      ->orIf(AccessResult::allowedIfHasPermission($account, 'administer tmgmt'));
  }

}

Members