EiekPrefectureAccessControlHandler.php 1.45 KB
Newer Older
giannisdag's avatar
giannisdag committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?php

namespace Drupal\iekreadydata;

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

/**
 * Access controller for the Eiek prefecture entity.
 *
 * @see \Drupal\iekreadydata\Entity\EiekPrefecture.
 */
class EiekPrefectureAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    /** @var \Drupal\iekreadydata\Entity\EiekPrefectureInterface $entity */
    switch ($operation) {
      case 'view':
        if (!$entity->isPublished()) {
          return AccessResult::allowedIfHasPermission($account, 'view unpublished eiek prefecture entities');
        }
        return AccessResult::allowedIfHasPermission($account, 'view published eiek prefecture entities');

      case 'update':
        return AccessResult::allowedIfHasPermission($account, 'edit eiek prefecture entities');

      case 'delete':
        return AccessResult::allowedIfHasPermission($account, 'delete eiek prefecture entities');
    }

    // Unknown operation, no opinion.
    return AccessResult::neutral();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    return AccessResult::allowedIfHasPermission($account, 'add eiek prefecture entities');
  }

}