protected function CalendarEventAccess::checkAccess in Opigno calendar event 3.x
Same name and namespace in other branches
- 8 src/CalendarEventAccess.php \Drupal\opigno_calendar_event\CalendarEventAccess::checkAccess()
File
- src/
CalendarEventAccess.php, line 18
Class
- CalendarEventAccess
- Defines access control handler for the calendar event entity type.
Namespace
Drupal\opigno_calendar_eventCode
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();
}
// Check if current user is a member.
if ($operation == 'view') {
$members = $entity
->get('field_calendar_event_members')
->getValue();
$account_id = $account
->id();
foreach ($members as $member) {
if ($member['target_id'] == $account_id) {
return AccessResult::allowed();
}
}
}
return AccessResult::forbidden();
}