You are here

FieldStorageConfigAccess.php in Field tools 8

File

src/EntityHandler/FieldStorageConfigAccess.php
View source
<?php

namespace Drupal\field_tools\EntityHandler;

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 field storage entity type.
 *
 * This just handles the 'delete' operation for our form.
 *
 * @see Drupal\field_tools\Form\FieldStorageConfigDeleteForm
 */
class FieldStorageConfigAccess extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    if ($operation == 'delete') {
      if ($entity
        ->isLocked()) {
        return AccessResult::forbidden()
          ->addCacheableDependency($entity);
      }
      else {
        return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity
          ->getTargetEntityTypeId() . ' fields')
          ->addCacheableDependency($entity);
      }
    }
    return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity
      ->getTargetEntityTypeId() . ' fields');
  }

}

Classes

Namesort descending Description
FieldStorageConfigAccess Defines the access control handler for the field storage entity type.