You are here

protected function FlagListItemAccessControlHandler::checkAccess in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/Access/FlagListItemAccessControlHandler.php \Drupal\flag_lists\Access\FlagListItemAccessControlHandler::checkAccess()

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/Access/FlagListItemAccessControlHandler.php, line 20

Class

FlagListItemAccessControlHandler
Access controller for the Flag list item entity.

Namespace

Drupal\flag_lists\Access

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  /** @var \Drupal\flag_lists\Entity\FlagListItemInterface $entity */
  switch ($operation) {
    case 'view':
      $flagService = \Drupal::service('flag');
      $baseFlag = $flagService
        ->getFlagById($entity
        ->getBaseFlag());
      if ($baseFlag
        ->isGlobal()) {
        return AccessResult::allowedIfHasPermission($account, 'access global flag lists');
      }
      else {
        return AccessResult::allowedIfHasPermission($account, 'view own flag lists');
      }
    case 'update':
    case 'delete':
      return AccessResult::allowedIfHasPermission($account, 'edit own flag lists');
  }

  // Unknown operation, no opinion.
  return AccessResult::neutral();
}