class GroupMembershipPermissionProvider in Group 2.0.x
Provides group permissions for the group_membership relation plugin.
Hierarchy
- class \Drupal\group\Plugin\Group\RelationHandler\GroupMembershipPermissionProvider implements PermissionProviderInterface uses PermissionProviderTrait
Expanded class hierarchy of GroupMembershipPermissionProvider
1 string reference to 'GroupMembershipPermissionProvider'
1 service uses GroupMembershipPermissionProvider
File
- src/
Plugin/ Group/ RelationHandler/ GroupMembershipPermissionProvider.php, line 8
Namespace
Drupal\group\Plugin\Group\RelationHandlerView source
class GroupMembershipPermissionProvider implements PermissionProviderInterface {
use PermissionProviderTrait;
/**
* Constructs a new GroupMembershipPermissionProvider.
*
* @param \Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface $parent
* The default permission provider.
*/
public function __construct(PermissionProviderInterface $parent) {
$this->parent = $parent;
}
/**
* {@inheritdoc}
*/
public function getPermission($operation, $target, $scope = 'any') {
// The following permissions are handled by the admin permission or have a
// different permission name.
if ($target === 'relation') {
switch ($operation) {
case 'create':
return FALSE;
case 'delete':
return $scope === 'own' ? 'leave group' : FALSE;
case 'update':
if ($scope === 'any') {
return FALSE;
}
break;
}
}
return $this->parent
->getPermission($operation, $target, $scope);
}
/**
* {@inheritdoc}
*/
public function buildPermissions() {
$permissions = $this->parent
->buildPermissions();
// Add in the join group permission.
$permissions['join group'] = [
'title' => 'Join group',
'allowed for' => [
'outsider',
],
];
// Alter the update own permission.
if ($name = $this->parent
->getPermission('update', 'relation', 'own')) {
$permissions[$name]['title'] = 'Edit own membership';
$permissions[$name]['allowed for'] = [
'member',
];
}
// Alter and rename the delete own permission.
if ($name = $this->parent
->getPermission('delete', 'relation', 'own')) {
$permissions[$name]['title'] = 'Leave group';
$permissions[$name]['allowed for'] = [
'member',
];
$permissions[$this
->getPermission('delete', 'relation', 'own')] = $permissions[$name];
unset($permissions[$name]);
}
// The following permissions are handled by the admin permission.
foreach ([
'create',
'update',
'delete',
] as $operation) {
if ($name = $this->parent
->getPermission($operation, 'relation')) {
unset($permissions[$name]);
}
}
// Update the labels of the default permissions.
$permissions[$this
->getAdminPermission()]['title'] = 'Administer group members';
$permissions[$this
->getPermission('view', 'relation')]['title'] = 'View individual group members';
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupMembershipPermissionProvider:: |
public | function |
Provides a list of group permissions the plugin exposes. Overrides PermissionProviderTrait:: |
|
GroupMembershipPermissionProvider:: |
public | function |
Gets the name of the permission for the given operation, target and scope. Overrides PermissionProviderTrait:: |
|
GroupMembershipPermissionProvider:: |
public | function | Constructs a new GroupMembershipPermissionProvider. | |
PermissionProviderTrait:: |
protected | property | Whether the plugin defines permissions for the target entity type. | |
PermissionProviderTrait:: |
protected | property | The entity type the plugin handler is for. | |
PermissionProviderTrait:: |
protected | property | Whether the target entity type implements the EntityOwnerInterface. | |
PermissionProviderTrait:: |
protected | property | Whether the target entity type implements the EntityPublishedInterface. | |
PermissionProviderTrait:: |
protected | function | Builds a permission with common translation arguments predefined. | |
PermissionProviderTrait:: |
public | function | 4 | |
PermissionProviderTrait:: |
public | function | ||
RelationHandlerTrait:: |
protected | property | The plugin definition. | |
RelationHandlerTrait:: |
protected | property | The entity type manager. | |
RelationHandlerTrait:: |
protected | property | The group relation manager. | |
RelationHandlerTrait:: |
protected | property | The parent relation handler in the decorator chain. | |
RelationHandlerTrait:: |
protected | property | The plugin ID as read from the definition. | |
RelationHandlerTrait:: |
protected | function | Gets the entity type manager service. | |
RelationHandlerTrait:: |
protected | function | Gets the group relation manager service. | |
RelationHandlerTrait:: |
public | function | Aliased as: traitInit |