You are here

public function FullEntityPermissionProvider::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

tests/modules/group_test_plugin/src/Plugin/Group/RelationHandler/FullEntityPermissionProvider.php, line 49

Class

FullEntityPermissionProvider
Provides all possible permissions.

Namespace

Drupal\group_test_plugin\Plugin\Group\RelationHandler

Code

public function buildPermissions() {
  $permissions = $this->parent
    ->buildPermissions();

  // Rename view any permissions.
  if ($name = $this->parent
    ->getPermission('view', 'entity')) {
    $permissions[$this
      ->getPermission('view', 'entity')] = $permissions[$name];
    unset($permissions[$name]);
  }
  if ($name = $this->parent
    ->getPermission('view unpublished', 'entity')) {
    $permissions[$this
      ->getPermission('view unpublished', 'entity')] = $permissions[$name];
    unset($permissions[$name]);
  }

  // Support view own permissions.
  $prefix = 'Entity:';
  if ($name = $this
    ->getPermission('view', 'entity', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View own %entity_type entities");
  }
  if ($name = $this
    ->getPermission('view unpublished', 'entity', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View own unpublished %entity_type entities");
  }
  return $permissions;
}