public function CRMCorePermissions::entityTypePermissions in CRM Core 8
Same name and namespace in other branches
- 8.3 src/CRMCorePermissions.php \Drupal\crm_core\CRMCorePermissions::entityTypePermissions()
- 8.2 src/CRMCorePermissions.php \Drupal\crm_core\CRMCorePermissions::entityTypePermissions()
Return permission names for a given CRM Core entity type.
Parameters
string $entity_type: Entity type string.
Return value
array Permissions.
File
- src/
CRMCorePermissions.php, line 24
Class
- CRMCorePermissions
- Defines a class containing permission callbacks.
Namespace
Drupal\crm_coreCode
public function entityTypePermissions($entity_type) {
$entity_info = \Drupal::EntityTypeManager()
->getDefinition($entity_type);
$labels = $this
->permissionLabels($entity_info);
$permissions = [];
// General 'administer' permission.
$permissions['administer ' . $entity_type . ' entities'] = [
'title' => $this
->t('Administer @entity_type', [
'@entity_type' => $labels['plural'],
]),
'description' => $this
->t('Allows users to perform any action on @entity_type.', [
'@entity_type' => $labels['plural'],
]),
'restrict access' => TRUE,
];
// Generic create and edit permissions.
$permissions['create ' . $entity_type . ' entities'] = [
'title' => $this
->t('Create @entity_type of any type', [
'@entity_type' => $labels['plural'],
]),
];
if ($entity_info
->hasKey('user')) {
$permissions['edit own ' . $entity_type . ' entities'] = [
'title' => $this
->t('Edit own @entity_type of any type', [
'@entity_type' => $labels['plural'],
]),
];
}
$permissions['edit any ' . $entity_type . ' entity'] = [
'title' => $this
->t('Edit any @entity_type of any type', [
'@entity_type' => $labels['singular'],
]),
'restrict access' => TRUE,
];
if ($entity_info
->hasKey('user')) {
$permissions['view own ' . $entity_type . ' entities'] = [
'title' => $this
->t('View own @entity_type of any type', [
'@entity_type' => $labels['plural'],
]),
];
}
$permissions['view any ' . $entity_type . ' entity'] = [
'title' => $this
->t('View any @entity_type of any type', [
'@entity_type' => $labels['singular'],
]),
'restrict access' => TRUE,
];
// Per-bundle create and edit permissions.
if ($entity_info
->hasKey('bundle')) {
$bundles = \Drupal::service('entity_type.bundle.info')
->getBundleInfo($entity_type);
foreach ($bundles as $bundle_name => $bundle_info) {
$permissions += $this
->bundlePermissions($bundle_name, $bundle_info, $entity_info);
}
}
return $permissions;
}