FeedbackMessageAccessControlHandler.php in Feedback 3.x
File
src/FeedbackMessageAccessControlHandler.php
View source
<?php
namespace Drupal\feedback;
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;
use Drupal\Core\Access\AccessResult;
class FeedbackMessageAccessControlHandler extends EntityAccessControlHandler {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
if (!$entity
->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished feedback message entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published feedback message entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit feedback message entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete feedback message entities');
}
return AccessResult::neutral();
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add feedback message entities');
}
protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
$administrative_fields = [
'path',
'user_id',
'status',
'created',
];
if ($operation == 'edit' && in_array($field_definition
->getName(), $administrative_fields, TRUE)) {
return AccessResult::allowedIfHasPermission($account, 'administer feedback message entities');
}
return parent::checkFieldAccess($operation, $field_definition, $account, $items);
}
}