You are here

protected function FeedAccessControlHandler::checkAccess in Feeds 8.3

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkAccess

File

src/FeedAccessControlHandler.php, line 20

Class

FeedAccessControlHandler
Defines an access controller for the feeds_feed entity.

Namespace

Drupal\feeds

Code

protected function checkAccess(EntityInterface $feed, $operation, AccountInterface $account) {
  $has_perm = $account
    ->hasPermission('administer feeds') || $account
    ->hasPermission("{$operation} {$feed->bundle()} feeds");
  switch ($operation) {
    case 'view':
    case 'create':
    case 'update':
      return AccessResult::allowedIf($has_perm);
    case 'import':
    case 'schedule_import':
    case 'clear':
      return AccessResult::allowedIf($has_perm && !$feed
        ->isLocked());
    case 'unlock':
      return AccessResult::allowedIf($has_perm && $feed
        ->isLocked());
    case 'delete':
      return AccessResult::allowedIf($has_perm && !$feed
        ->isLocked() && !$feed
        ->isNew());
    default:
      return AccessResult::neutral();
  }
}