function entity_permissions in Coder 8.3
Same name and namespace in other branches
- 8.3.x tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc \entity_permissions()
Provides the necessary user permissions for entity operations.
Parameters
string $entity_type_id: The entity type.
string $operation: The operation, one of 'view', 'create', 'update' or 'delete'.
Return value
array The set of user permission strings.
File
- tests/
Drupal/ WhiteSpace/ ScopeIndentUnitTest.inc, line 70
Code
function entity_permissions($entity_type_id, $operation) {
switch ($entity_type_id) {
case 'entity_test':
switch ($operation) {
case 'view':
return [
'view test entity',
];
case 'create':
case 'update':
case 'delete':
return [
'administer entity_test content',
];
}
case 'node':
switch ($operation) {
case 'view':
return [
'access content',
];
case 'create':
return [
'create resttest content',
];
case 'update':
return [
'edit any resttest content',
];
case 'delete':
return [
'delete any resttest content',
];
}
case 'comment':
switch ($operation) {
case 'view':
return [
'access comments',
];
case 'create':
return [
'post comments',
'skip comment approval',
];
case 'update':
return [
'edit own comments',
];
case 'delete':
return [
'administer comments',
];
}
break;
case 'user':
switch ($operation) {
case 'view':
return [
'access user profiles',
];
default:
return [
'administer users',
];
}
default:
if (isConfigEntity($entity_type_id)) {
$entity_type = \Drupal::entityTypeManager()
->getDefinition($entity_type_id);
if ($admin_permission = $entity_type
->getAdminPermission()) {
return [
$admin_permission,
];
}
}
}
return [];
}