openquestions-1.0.x-dev/src/Access/OqApplicationHistoryAccessControlHandler.php
src/Access/OqApplicationHistoryAccessControlHandler.php
<?php
namespace Drupal\openquestions\Access;
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 oq application history entity type.
*/
class OqApplicationHistoryAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view oq application history');
case 'update':
return AccessResult::allowedIfHasPermissions(
$account,
['edit oq application history', 'administer oq application history'],
'OR',
);
case 'delete':
return AccessResult::allowedIfHasPermissions(
$account,
['delete oq application history', 'administer oq application history'],
'OR',
);
default:
// No opinion.
return AccessResult::neutral();
}
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermissions(
$account,
['create oq application history', 'administer oq application history'],
'OR',
);
}
}
