You are here

protected function UncacheableEntityPermissionProvider::buildEntityTypePermissions in Entity API 8

Builds permissions for the entity_type granularity.

Parameters

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

Return value

array The permissions.

Overrides EntityPermissionProviderBase::buildEntityTypePermissions

File

src/UncacheableEntityPermissionProvider.php, line 54

Class

UncacheableEntityPermissionProvider
Provides generic entity permissions which are cached per user.

Namespace

Drupal\entity

Code

protected function buildEntityTypePermissions(EntityTypeInterface $entity_type) {
  $permissions = parent::buildEntityTypePermissions($entity_type);
  $entity_type_id = $entity_type
    ->id();
  $has_owner = $entity_type
    ->entityClassImplements(EntityOwnerInterface::class);
  $plural_label = $entity_type
    ->getPluralLabel();
  if ($has_owner) {
    $permissions["view any {$entity_type_id}"] = [
      'title' => $this
        ->t('View any @type', [
        '@type' => $plural_label,
      ]),
    ];
    $permissions["view own {$entity_type_id}"] = [
      'title' => $this
        ->t('View own @type', [
        '@type' => $plural_label,
      ]),
    ];
  }
  else {
    $permissions["view {$entity_type_id}"] = [
      'title' => $this
        ->t('View @type', [
        '@type' => $plural_label,
      ]),
    ];
  }
  return $permissions;
}