12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace Drupal\statusmessage;
- use Drupal\Core\Entity\EntityAccessControlHandler;
- use Drupal\Core\Entity\EntityInterface;
- use Drupal\Core\Session\AccountInterface;
- use Drupal\Core\Access\AccessResult;
- /**
- * Access controller for the Status entity.
- *
- * @see \Drupal\statusmessage\Entity\Status.
- */
- class StatusAccessControlHandler extends EntityAccessControlHandler {
- /**
- * {@inheritdoc}
- */
- protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
- /** @var \Drupal\statusmessage\StatusInterface $entity */
- switch ($operation) {
- case 'view':
- if (!$entity->isPublished()) {
- return AccessResult::allowedIfHasPermission($account, 'view unpublished status entities');
- }
- return AccessResult::allowedIfHasPermission($account, 'view published status entities');
- case 'update':
- return AccessResult::allowedIfHasPermission($account, 'edit status entities');
- case 'delete':
- return AccessResult::allowedIfHasPermission($account, 'delete status entities');
- }
- // Unknown operation, no opinion.
- return AccessResult::neutral();
- }
- /**
- * {@inheritdoc}
- */
- protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
- return AccessResult::allowedIfHasPermission($account, 'add status entities');
- }
- }
|