You are here

protected function CalendarEventAccess::checkAccess in Opigno calendar event 8

Same name and namespace in other branches
  1. 3.x src/CalendarEventAccess.php \Drupal\opigno_calendar_event\CalendarEventAccess::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 EntityAccessControlHandlerBase::checkAccess

File

src/CalendarEventAccess.php, line 18

Class

CalendarEventAccess
Defines access control handler for the calendar event entity type.

Namespace

Drupal\opigno_calendar_event

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($account
    ->hasPermission($operation . ' opigno_calendar_event')) {
    return AccessResult::allowed();
  }
  if ($entity
    ->get('uid')->target_id == $account
    ->id() && $account
    ->hasPermission($operation . ' own opigno calendar event')) {
    return AccessResult::allowed();
  }
  return AccessResult::forbidden();
}