public function EventAddAccessCheck::access in Booking and Availability Management Tools for Drupal 8
Checks access to the event add page for the event type.
Parameters
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
\Drupal\bat_event\EventTypeInterface $event_type: (optional) The event type. If not specified, access is allowed if there exists at least one event type for which the user may create a event.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- modules/
bat_event/ src/ Access/ EventAddAccessCheck.php, line 50 - Contains \Drupal\bat_event\Access\EventAddAccessCheck.
Class
- EventAddAccessCheck
- Determines access to for event add pages.
Namespace
Drupal\bat_event\AccessCode
public function access(AccountInterface $account, EventTypeInterface $event_type = NULL) {
$access_control_handler = $this->entityTypeManager
->getAccessControlHandler('bat_event');
if ($account
->hasPermission('administer bat_event_type entities')) {
// There are no type bundles defined that the user has permission to
// create, but the user does have the permission to administer the content
// types, so grant them access to the page anyway.
return AccessResult::allowed();
}
if ($event_type) {
return $access_control_handler
->createAccess($event_type
->id(), $account, [], TRUE);
}
$bundles = bat_event_get_types();
foreach ($bundles as $bundle) {
if (bat_event_access(bat_event_create([
'type' => $bundle
->id(),
'uid' => 0,
]), 'create', $account
->getAccount())
->isAllowed()) {
return AccessResult::allowed();
}
}
return AccessResult::forbidden();
}