You are here

NodeTypeAccessControlHandler.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/node/src/NodeTypeAccessControlHandler.php

Namespace

Drupal\node

File

core/modules/node/src/NodeTypeAccessControlHandler.php
View source
<?php

/**
 * @file
 * Contains \Drupal\node\NodeTypeAccessControlHandler.
 */
namespace Drupal\node;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Defines the access control handler for the node type entity type.
 *
 * @see \Drupal\node\Entity\NodeType
 */
class NodeTypeAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'access content');
        break;
      case 'delete':
        if ($entity
          ->isLocked()) {
          return AccessResult::forbidden()
            ->cacheUntilEntityChanges($entity);
        }
        else {
          return parent::checkAccess($entity, $operation, $account)
            ->cacheUntilEntityChanges($entity);
        }
        break;
      default:
        return parent::checkAccess($entity, $operation, $account);
        break;
    }
  }

}

Classes

Namesort descending Description
NodeTypeAccessControlHandler Defines the access control handler for the node type entity type.