public function TypeGroupAddAccessCheck::access in Booking and Availability Management Tools for Drupal 8
Checks access to the type group add page for the type group bundle.
Parameters
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
\Drupal\bat\TypeGroupBundleInterface $type_group_bundle: (optional) The type group bundle. If not specified, access is allowed if there exists at least one type group bundle for which the user may create a type group.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- src/
Access/ TypeGroupAddAccessCheck.php, line 50 - Contains \Drupal\bat\Access\TypeGroupAddAccessCheck.
Class
- TypeGroupAddAccessCheck
- Determines access to for type group add pages.
Namespace
Drupal\bat\AccessCode
public function access(AccountInterface $account, TypeGroupBundleInterface $type_group_bundle = NULL) {
$access_control_handler = $this->entityTypeManager
->getAccessControlHandler('bat_type_group');
if ($account
->hasPermission('administer bat_type_group_bundle 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 ($type_group_bundle) {
return $access_control_handler
->createAccess($type_group_bundle
->id(), $account, [], TRUE);
}
$bundles = bat_type_group_get_bundles();
foreach ($bundles as $bundle) {
if (bat_entity_access(bat_type_group_create([
'type' => $bundle
->id(),
'uid' => 0,
]), 'create', $account
->getAccount())
->isAllowed()) {
return AccessResult::allowed();
}
}
return AccessResult::forbidden();
}