FlaggingCollectionAccessControlHandler.php in Flag Lists 8
File
src/Access/FlaggingCollectionAccessControlHandler.php
View source
<?php
namespace Drupal\flag_lists\Access;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
class FlaggingCollectionAccessControlHandler extends EntityAccessControlHandler {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
if ($account
->id() == $entity
->getOwner()
->id()) {
return AccessResult::allowedIfHasPermission($account, 'view own flag lists');
}
elseif ($entity
->getBaseFlag()
->isGlobal()) {
return AccessResult::allowedIfHasPermission($account, 'access global flag lists');
}
else {
return AccessResult::allowedIfHasPermission($account, 'administer flag lists');
}
case 'update':
case 'delete':
if ($account
->id() == $entity
->getOwner()
->id()) {
return AccessResult::allowedIfHasPermission($account, 'edit own flag lists');
}
else {
return AccessResult::allowedIfHasPermission($account, 'administer flag lists');
}
}
return AccessResult::neutral();
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add flag lists');
}
}