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; } /** * Builds permissions for the bundle granularity. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return array * The permissions. */ protected function buildBundlePermissions(EntityTypeInterface $entity_type) { $permissions = parent::buildBundlePermissions($entity_type); $entity_type_id = $entity_type->id(); $bundles = $this->entityTypeBundleInfo->getBundleInfo($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, ]), ]; } foreach ($bundles as $bundle_name => $bundle_info) { if ($has_owner) { $permissions["view any {$bundle_name} {$entity_type_id}"] = [ 'title' => $this->t('@bundle: View any @type', [ '@bundle' => $bundle_info['label'], '@type' => $plural_label, ]), ]; $permissions["view own {$bundle_name} {$entity_type_id}"] = [ 'title' => $this->t('@bundle: View own @type', [ '@bundle' => $bundle_info['label'], '@type' => $plural_label, ]), ]; } else { $permissions["view {$bundle_name} {$entity_type_id}"] = [ 'title' => $this->t('@bundle: View @type', [ '@bundle' => $bundle_info['label'], '@type' => $plural_label, ]), ]; } } return $permissions; } }