You are here

protected function EntityPermissionProvider::buildBundlePermissions in Entity API 8

Builds permissions for the bundle granularity.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

Return value

array The permissions.

Overrides EntityPermissionProviderBase::buildBundlePermissions

File

src/EntityPermissionProvider.php, line 75

Class

EntityPermissionProvider
Provides generic entity permissions.

Namespace

Drupal\entity

Code

protected function buildBundlePermissions(EntityTypeInterface $entity_type) {
  $permissions = parent::buildBundlePermissions($entity_type);
  $entity_type_id = $entity_type
    ->id();
  $bundles = $this->entityTypeBundleInfo
    ->getBundleInfo($entity_type_id);
  $plural_label = $entity_type
    ->getPluralLabel();
  $permissions["view {$entity_type_id}"] = [
    'title' => $this
      ->t('View @type', [
      '@type' => $plural_label,
    ]),
  ];
  foreach ($bundles as $bundle_name => $bundle_info) {
    $permissions["view {$bundle_name} {$entity_type_id}"] = [
      'title' => $this
        ->t('@bundle: View @type', [
        '@bundle' => $bundle_info['label'],
        '@type' => $plural_label,
      ]),
    ];
  }
  return $permissions;
}