public function CRMCorePermissions::entityTypePermissions in CRM Core 8.2
Same name and namespace in other branches
- 8.3 src/CRMCorePermissions.php \Drupal\crm_core\CRMCorePermissions::entityTypePermissions()
- 8 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 30 - Contains \Drupal\crm_core\CRMCorePermissions.
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 = array();
// General 'administer' permission.
$permissions['administer ' . $entity_type . ' entities'] = array(
'title' => $this
->t('Administer @entity_type', array(
'@entity_type' => $labels['plural'],
)),
'description' => $this
->t('Allows users to perform any action on @entity_type.', array(
'@entity_type' => $labels['plural'],
)),
'restrict access' => TRUE,
);
// Generic create and edit permissions.
$permissions['create ' . $entity_type . ' entities'] = array(
'title' => $this
->t('Create @entity_type of any type', array(
'@entity_type' => $labels['plural'],
)),
);
if ($entity_info
->hasKey('user')) {
$permissions['edit own ' . $entity_type . ' entities'] = array(
'title' => $this
->t('Edit own @entity_type of any type', array(
'@entity_type' => $labels['plural'],
)),
);
}
$permissions['edit any ' . $entity_type . ' entity'] = array(
'title' => $this
->t('Edit any @entity_type of any type', array(
'@entity_type' => $labels['singular'],
)),
'restrict access' => TRUE,
);
if ($entity_info
->hasKey('user')) {
$permissions['view own ' . $entity_type . ' entities'] = array(
'title' => $this
->t('View own @entity_type of any type', array(
'@entity_type' => $labels['plural'],
)),
);
}
$permissions['view any ' . $entity_type . ' entity'] = array(
'title' => $this
->t('View any @entity_type of any type', array(
'@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;
}