You are here

VoteAccessControlHandler.php in Voting API 8.3

Namespace

Drupal\votingapi

File

src/VoteAccessControlHandler.php
View source
<?php

namespace Drupal\votingapi;

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

/**
 * Defines the access control handler for the vote entity type.
 *
 * @see \Drupal\votingapi\Entity\Vote
 */
class VoteAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    return $operation == 'delete' ? AccessResult::allowedIfHasPermission($account, 'delete votes') : AccessResult::allowed();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    return AccessResult::allowed();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
    return AccessResult::allowed();
  }

}

Classes

Namesort descending Description
VoteAccessControlHandler Defines the access control handler for the vote entity type.