ProfilePermissionProvider.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Drupal\profile;
  3. use Drupal\Core\Entity\EntityTypeInterface;
  4. use Drupal\entity\EntityPermissionProvider;
  5. /**
  6. * Providers Profile entity permissions.
  7. *
  8. * Extends the Entity API permission provider to support bundle based view
  9. * permissions.
  10. */
  11. class ProfilePermissionProvider extends EntityPermissionProvider {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. protected function buildBundlePermissions(EntityTypeInterface $entity_type) {
  16. $permissions = parent::buildBundlePermissions($entity_type);
  17. $singular_label = $entity_type->getSingularLabel();
  18. $entity_type_id = $entity_type->id();
  19. $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
  20. foreach ($bundles as $bundle_name => $bundle_info) {
  21. $permissions["view any {$bundle_name} {$entity_type_id}"] = [
  22. 'title' => $this->t('@bundle: View any @type', [
  23. '@bundle' => $bundle_info['label'],
  24. '@type' => $singular_label,
  25. ]),
  26. ];
  27. $permissions["view own {$bundle_name} {$entity_type_id}"] = [
  28. 'title' => $this->t('@bundle: View own @type', [
  29. '@bundle' => $bundle_info['label'],
  30. '@type' => $singular_label,
  31. ]),
  32. ];
  33. }
  34. return $permissions;
  35. }
  36. }