public function EntityPermissionProviderBase::buildPermissions in Entity API 8
Builds permissions for the given entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.
Return value
array The permissions.
Overrides EntityPermissionProviderInterface::buildPermissions
File
- src/
EntityPermissionProviderBase.php, line 49
Class
- EntityPermissionProviderBase
- @internal
Namespace
Drupal\entityCode
public function buildPermissions(EntityTypeInterface $entity_type) {
$entity_type_id = $entity_type
->id();
$has_owner = $entity_type
->entityClassImplements(EntityOwnerInterface::class);
$plural_label = $entity_type
->getPluralLabel();
$permissions = [];
$admin_permission = $entity_type
->getAdminPermission() ?: "administer {$entity_type_id}";
$permissions[$admin_permission] = [
'title' => $this
->t('Administer @type', [
'@type' => $plural_label,
]),
'restrict access' => TRUE,
];
if ($entity_type
->hasLinkTemplate('collection')) {
$permissions["access {$entity_type_id} overview"] = [
'title' => $this
->t('Access the @type overview page', [
'@type' => $plural_label,
]),
];
}
if ($has_owner && $entity_type
->entityClassImplements(EntityPublishedInterface::class)) {
$permissions["view own unpublished {$entity_type_id}"] = [
'title' => $this
->t('View own unpublished @type', [
'@type' => $plural_label,
]),
];
}
// Generate the other permissions based on granularity.
if ($entity_type
->getPermissionGranularity() === 'entity_type') {
$permissions += $this
->buildEntityTypePermissions($entity_type);
}
else {
$permissions += $this
->buildBundlePermissions($entity_type);
}
return $this
->processPermissions($permissions, $entity_type);
}