You are here

public function GroupMembershipPermissionProvider::buildPermissions in Group 2.0.x

Provides a list of group permissions the plugin exposes.

If you have some group permissions that would only make sense when your plugin is installed, you may define those here. They will not be shown on the permission configuration form unless the plugin is installed.

Return value

array An array of group permissions, see GroupPermissionHandlerInterface for the structure of a group permission.

Overrides PermissionProviderTrait::buildPermissions

See also

GroupPermissionHandlerInterface::getPermissions()

File

src/Plugin/Group/RelationHandler/GroupMembershipPermissionProvider.php, line 49

Class

GroupMembershipPermissionProvider
Provides group permissions for the group_membership relation plugin.

Namespace

Drupal\group\Plugin\Group\RelationHandler

Code

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;
}