function bat_entity_access_permissions in Booking and Availability Management Tools for Drupal 8
Same name and namespace in other branches
- 7 bat.module \bat_entity_access_permissions()
Return permission names for a given entity type.
5 calls to bat_entity_access_permissions()
- BookingPermissions::permissions in modules/
bat_booking/ src/ BookingPermissions.php - EventPermissions::permissions in modules/
bat_event/ src/ EventPermissions.php - Returns an array of filter permissions.
- EventSeriesPermissions::permissions in modules/
bat_event_series/ src/ EventSeriesPermissions.php - Returns an array of filter permissions.
- TypeGroupPermissions::permissions in src/
TypeGroupPermissions.php - Returns an array of filter permissions.
- UnitPermissions::permissions in modules/
bat_unit/ src/ UnitPermissions.php - Returns an array of filter permissions.
File
- ./
bat.module, line 229 - Contains bat.module..
Code
function bat_entity_access_permissions($entity_type) {
$entity_info = \Drupal::entityTypeManager()
->getDefinition($entity_type);
$label = $entity_info
->getLabel()
->__toString();
$permissions = [];
// General 'bypass' permission.
$permissions['bypass ' . $entity_type . ' entities access'] = [
'title' => t('Bypass access to @entity_type', [
'@entity_type' => $label,
]),
'description' => t('Allows users to perform any action on @entity_type.', [
'@entity_type' => $label,
]),
'restrict access' => TRUE,
];
// Generic create and edit permissions.
$permissions['create ' . $entity_type . ' entities'] = [
'title' => t('Create @entity_type of any type', [
'@entity_type' => $label,
]),
];
if ($entity_info
->getKey('uid') !== FALSE) {
$permissions['view own ' . $entity_type . ' entities'] = [
'title' => t('View own @entity_type of any type', [
'@entity_type' => $label,
]),
];
}
$permissions['view any ' . $entity_type . ' entity'] = [
'title' => t('View any @entity_type of any type', [
'@entity_type' => $label,
]),
'restrict access' => TRUE,
];
if ($entity_info
->getKey('uid') !== FALSE) {
$permissions['update own ' . $entity_type . ' entities'] = [
'title' => t('Edit own @entity_type of any type', [
'@entity_type' => $label,
]),
];
}
$permissions['update any ' . $entity_type . ' entity'] = [
'title' => t('Edit any @entity_type of any type', [
'@entity_type' => $label,
]),
'restrict access' => TRUE,
];
if ($entity_info
->getKey('uid') !== FALSE) {
$permissions['delete own ' . $entity_type . ' entities'] = [
'title' => t('Delete own @entity_type of any type', [
'@entity_type' => $label,
]),
];
}
$permissions['delete any ' . $entity_type . ' entity'] = [
'title' => t('Delete any @entity_type of any type', [
'@entity_type' => $label,
]),
'restrict access' => TRUE,
];
// Per-bundle create and edit permissions.
foreach (\Drupal::service('entity_type.bundle.info')
->getBundleInfo($entity_type) as $bundle_name => $bundle_info) {
$permissions['create ' . $entity_type . ' entities of bundle ' . $bundle_name] = [
'title' => t('Create %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
];
if ($entity_info
->getKey('uid') !== FALSE) {
$permissions['view own ' . $entity_type . ' entities of bundle ' . $bundle_name] = [
'title' => t('View own %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
];
}
$permissions['view any ' . $entity_type . ' entity of bundle ' . $bundle_name] = [
'title' => t('View any %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
'restrict access' => TRUE,
];
if ($entity_info
->getKey('uid') !== FALSE) {
$permissions['update own ' . $entity_type . ' entities of bundle ' . $bundle_name] = [
'title' => t('Edit own %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
];
}
$permissions['update any ' . $entity_type . ' entity of bundle ' . $bundle_name] = [
'title' => t('Edit any %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
'restrict access' => TRUE,
];
if ($entity_info
->getKey('uid') !== FALSE) {
$permissions['delete own ' . $entity_type . ' entities of bundle ' . $bundle_name] = [
'title' => t('Delete own %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
];
}
$permissions['delete any ' . $entity_type . ' entity of bundle ' . $bundle_name] = [
'title' => t('Delete any %bundle @entity_type', [
'@entity_type' => $label,
'%bundle' => $bundle_info['label'],
]),
'restrict access' => TRUE,
];
}
return $permissions;
}