3 namespace Drupal\entity;
5 use Drupal\Core\Entity\EntityTypeInterface;
8 * Provides generic entity permissions which are still cacheable.
12 * - administer $entity_type
13 * - access $entity_type overview
15 * - view own unpublished $entity_type
16 * - update (own|any) ($bundle) $entity_type
17 * - delete (own|any) ($bundle) $entity_type
18 * - create $bundle $entity_type
20 * This class does not support "view own ($bundle) $entity_type", because this
21 * results in caching per user. If you need this use case, please use
22 * \Drupal\entity\UncacheableEntityPermissionProvider instead.
24 * Intended for content entity types, since config entity types usually rely
25 * on a single "administer" permission.
29 * "access" = "Drupal\entity\EntityAccessControlHandler",
30 * "permission_provider" = "Drupal\entity\EntityPermissionProvider",
34 * @see \Drupal\entity\EntityAccessControlHandler
35 * @see \Drupal\entity\EntityPermissions
37 class EntityPermissionProvider extends EntityPermissionProviderBase {
42 public function buildPermissions(EntityTypeInterface $entity_type) {
43 $entity_type_id = $entity_type->id();
44 $plural_label = $entity_type->getPluralLabel();
46 $permissions = parent::buildPermissions($entity_type);
48 // View permissions are the same for both granularities.
49 $permissions["view {$entity_type_id}"] = [
50 'title' => $this->t('View @type', [
51 '@type' => $plural_label,
55 return $this->processPermissions($permissions, $entity_type);