function bat_unit_access_filter in Booking and Availability Management Tools for Drupal 8
Same name and namespace in other branches
- 7 modules/bat_unit/bat_unit.module \bat_unit_access_filter()
Filters units based on permissions for multiple values.
File
- modules/
bat_unit/ bat_unit.module, line 172 - Manage units - Units are things that can be booked for some period of time. (e.g. rooms - but also villas bungalows, cars, drills, you-get-the-idea etc.)
Code
function bat_unit_access_filter($operation, $units = [], $account = NULL) {
$filtered_units = [];
// If no user object is supplied, the access check is for the current user.
if (empty($account)) {
$account = \Drupal::currentUser();
}
foreach ($units as $key => $unit) {
if (bat_unit_access($unit, $operation, $account)
->isAllowed()) {
$filtered_units[$key] = $unit;
}
}
return $filtered_units;
}