entity_legal-4.0.x-dev/src/EntityLegalDocumentAccessControlHandler.php

src/EntityLegalDocumentAccessControlHandler.php
<?php

declare(strict_types=1);

namespace Drupal\entity_legal;

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

/**
 * Access control handler for the entity legal document entity type.
 *
 * @see \Drupal\entity_legal\Entity\EntityLegalDocument.
 */
class EntityLegalDocumentAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account): AccessResultInterface {
    // Allow all users who can administer the module to do anything.
    if ($account->hasPermission('administer entity legal')) {
      return AccessResult::allowed();
    }

    /** @var \Drupal\entity_legal\EntityLegalDocumentInterface $entity */
    if ($operation == 'view' && $account->hasPermission($entity->getPermissionView())) {
      return AccessResult::allowed();
    }

    return parent::checkAccess($entity, $operation, $account);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc