NodeTypeAccessControlHandler.php 1.01 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\node;

5
use Drupal\Core\Access\AccessResult;
6
use Drupal\Core\Entity\EntityAccessControlHandler;
7 8 9 10
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
11
 * Defines the access control handler for the node type entity type.
12
 *
13
 * @see \Drupal\node\Entity\NodeType
14
 */
15
class NodeTypeAccessControlHandler extends EntityAccessControlHandler {
16 17 18 19

  /**
   * {@inheritdoc}
   */
20
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
21 22 23 24 25 26
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'access content');

      case 'delete':
        if ($entity->isLocked()) {
27
          return AccessResult::forbidden()->addCacheableDependency($entity);
28 29
        }
        else {
30
          return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
31 32 33 34
        }
        break;

      default:
35
        return parent::checkAccess($entity, $operation, $account);
36

37
    }
38 39
  }

40
}