You are here

protected function CRMCorePermissions::bundlePermissions in CRM Core 8.2

Same name and namespace in other branches
  1. 8.3 src/CRMCorePermissions.php \Drupal\crm_core\CRMCorePermissions::bundlePermissions()
  2. 8 src/CRMCorePermissions.php \Drupal\crm_core\CRMCorePermissions::bundlePermissions()

Define per-bundle permissions.

1 call to CRMCorePermissions::bundlePermissions()
CRMCorePermissions::entityTypePermissions in src/CRMCorePermissions.php
Return permission names for a given CRM Core entity type.

File

src/CRMCorePermissions.php, line 82
Contains \Drupal\crm_core\CRMCorePermissions.

Class

CRMCorePermissions
Defines a class containing permission callbacks.

Namespace

Drupal\crm_core

Code

protected function bundlePermissions($bundle_name, array $bundle_info, EntityTypeInterface $entity_info) {
  $labels = $this
    ->permissionLabels($entity_info);
  $permissions['create ' . $entity_info
    ->id() . ' entities of bundle ' . $bundle_name] = array(
    'title' => $this
      ->t('Create %bundle @entity_type', array(
      '@entity_type' => $labels['plural'],
      '%bundle' => $bundle_info['label'],
    )),
  );
  if ($entity_info
    ->hasKey('user')) {
    $permissions['edit own ' . $entity_info
      ->id() . ' entities of bundle ' . $bundle_name] = array(
      'title' => $this
        ->t('Edit own %bundle @entity_type', array(
        '@entity_type' => $labels['plural'],
        '%bundle' => $bundle_info['label'],
      )),
    );
  }
  $permissions['edit any ' . $entity_info
    ->id() . ' entity of bundle ' . $bundle_name] = array(
    'title' => $this
      ->t('Edit any %bundle @entity_type', array(
      '@entity_type' => $labels['singular'],
      '%bundle' => $bundle_info['label'],
    )),
    'restrict access' => TRUE,
  );
  if ($entity_info
    ->hasKey('user')) {
    $permissions['delete own ' . $entity_info
      ->id() . ' entities of bundle ' . $bundle_name] = array(
      'title' => $this
        ->t('Delete own %bundle @entity_type', array(
        '@entity_type' => $labels['plural'],
        '%bundle' => $bundle_info['label'],
      )),
    );
  }
  $permissions['delete any ' . $entity_info
    ->id() . ' entity of bundle ' . $bundle_name] = array(
    'title' => $this
      ->t('Delete any %bundle @entity_type', array(
      '@entity_type' => $labels['singular'],
      '%bundle' => $bundle_info['label'],
    )),
    'restrict access' => TRUE,
  );
  if ($entity_info
    ->hasKey('user')) {
    $permissions['view own ' . $entity_info
      ->id() . ' entities of bundle ' . $bundle_name] = array(
      'title' => $this
        ->t('View own %bundle @entity_type', array(
        '@entity_type' => $labels['plural'],
        '%bundle' => $bundle_info['label'],
      )),
    );
  }
  $permissions['view any ' . $entity_info
    ->id() . ' entity of bundle ' . $bundle_name] = array(
    'title' => $this
      ->t('View any %bundle @entity_type', array(
      '@entity_type' => $labels['singular'],
      '%bundle' => $bundle_info['label'],
    )),
    'restrict access' => TRUE,
  );
  return $permissions;
}