You are here

protected function EntityPermissionProviderBase::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.

3 calls to EntityPermissionProviderBase::buildBundlePermissions()
EntityPermissionProvider::buildBundlePermissions in src/EntityPermissionProvider.php
Builds permissions for the bundle granularity.
EntityPermissionProviderBase::buildPermissions in src/EntityPermissionProviderBase.php
Builds permissions for the given entity type.
UncacheableEntityPermissionProvider::buildBundlePermissions in src/UncacheableEntityPermissionProvider.php
Builds permissions for the bundle granularity.
2 methods override EntityPermissionProviderBase::buildBundlePermissions()
EntityPermissionProvider::buildBundlePermissions in src/EntityPermissionProvider.php
Builds permissions for the bundle granularity.
UncacheableEntityPermissionProvider::buildBundlePermissions in src/UncacheableEntityPermissionProvider.php
Builds permissions for the bundle granularity.

File

src/EntityPermissionProviderBase.php, line 194

Class

EntityPermissionProviderBase
@internal

Namespace

Drupal\entity

Code

protected function buildBundlePermissions(EntityTypeInterface $entity_type) {
  $entity_type_id = $entity_type
    ->id();
  $bundles = $this->entityTypeBundleInfo
    ->getBundleInfo($entity_type_id);
  $has_owner = $entity_type
    ->entityClassImplements(EntityOwnerInterface::class);
  $has_duplicate_form = $entity_type
    ->hasLinkTemplate('duplicate-form');
  $singular_label = $entity_type
    ->getSingularLabel();
  $plural_label = $entity_type
    ->getPluralLabel();
  $permissions = [];
  foreach ($bundles as $bundle_name => $bundle_info) {
    $permissions["create {$bundle_name} {$entity_type_id}"] = [
      'title' => $this
        ->t('@bundle: Create @type', [
        '@bundle' => $bundle_info['label'],
        '@type' => $plural_label,
      ]),
    ];
    if ($has_owner) {
      $permissions["update any {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('@bundle: Update any @type', [
          '@bundle' => $bundle_info['label'],
          '@type' => $singular_label,
        ]),
      ];
      $permissions["update own {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('@bundle: Update own @type', [
          '@bundle' => $bundle_info['label'],
          '@type' => $plural_label,
        ]),
      ];
      if ($has_duplicate_form) {
        $permissions["duplicate any {$bundle_name} {$entity_type_id}"] = [
          'title' => $this
            ->t('@bundle: Duplicate any @type', [
            '@bundle' => $bundle_info['label'],
            '@type' => $singular_label,
          ]),
        ];
        $permissions["duplicate own {$bundle_name} {$entity_type_id}"] = [
          'title' => $this
            ->t('@bundle: Duplicate own @type', [
            '@bundle' => $bundle_info['label'],
            '@type' => $plural_label,
          ]),
        ];
      }
      $permissions["delete any {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('@bundle: Delete any @type', [
          '@bundle' => $bundle_info['label'],
          '@type' => $singular_label,
        ]),
      ];
      $permissions["delete own {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('@bundle: Delete own @type', [
          '@bundle' => $bundle_info['label'],
          '@type' => $plural_label,
        ]),
      ];
    }
    else {
      $permissions["update {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('@bundle: Update @type', [
          '@bundle' => $bundle_info['label'],
          '@type' => $plural_label,
        ]),
      ];
      if ($has_duplicate_form) {
        $permissions["duplicate {$bundle_name} {$entity_type_id}"] = [
          'title' => $this
            ->t('@bundle: Duplicate @type', [
            '@bundle' => $bundle_info['label'],
            '@type' => $plural_label,
          ]),
        ];
      }
      $permissions["delete {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('@bundle: Delete @type', [
          '@bundle' => $bundle_info['label'],
          '@type' => $plural_label,
        ]),
      ];
    }
  }
  return $permissions;
}