You are here

protected function OgEventSubscriber::generateEntityOperationPermissionList in Organic groups 8

Helper method to generate entity operation permissions for a given bundle.

Parameters

string $group_content_entity_type_id: The entity type ID for which to generate the permission list.

string $group_content_bundle_id: The bundle ID for which to generate the permission list.

Return value

array An array of permission names and descriptions.

1 call to OgEventSubscriber::generateEntityOperationPermissionList()
OgEventSubscriber::getDefaultEntityOperationPermissions in src/EventSubscriber/OgEventSubscriber.php
Returns a list of generic entity operation permissions for group content.

File

src/EventSubscriber/OgEventSubscriber.php, line 301

Class

OgEventSubscriber
Event subscribers for Organic Groups.

Namespace

Drupal\og\EventSubscriber

Code

protected function generateEntityOperationPermissionList($group_content_entity_type_id, $group_content_bundle_id) {
  $permissions = [];
  $entity_info = $this->entityTypeManager
    ->getDefinition($group_content_entity_type_id);
  $bundle_info = $this->entityTypeBundleInfo
    ->getBundleInfo($group_content_entity_type_id)[$group_content_bundle_id];

  // Build standard list of permissions for this bundle.
  $args = [
    '%bundle' => $bundle_info['label'],
    '@entity' => $entity_info
      ->getPluralLabel(),
  ];

  // @todo This needs to support all entity operations for the given entity
  //   type, not just the standard CRUD operations.
  // @see https://github.com/amitaibu/og/issues/222
  $operations = [
    [
      'name' => "create {$group_content_bundle_id} {$group_content_entity_type_id}",
      'title' => $this
        ->t('Create %bundle @entity', $args),
      'operation' => 'create',
    ],
    [
      'name' => "update own {$group_content_bundle_id} {$group_content_entity_type_id}",
      'title' => $this
        ->t('Edit own %bundle @entity', $args),
      'operation' => 'update',
      'owner' => TRUE,
    ],
    [
      'name' => "update any {$group_content_bundle_id} {$group_content_entity_type_id}",
      'title' => $this
        ->t('Edit any %bundle @entity', $args),
      'operation' => 'update',
      'owner' => FALSE,
    ],
    [
      'name' => "delete own {$group_content_bundle_id} {$group_content_entity_type_id}",
      'title' => $this
        ->t('Delete own %bundle @entity', $args),
      'operation' => 'delete',
      'owner' => TRUE,
    ],
    [
      'name' => "delete any {$group_content_bundle_id} {$group_content_entity_type_id}",
      'title' => $this
        ->t('Delete any %bundle @entity', $args),
      'operation' => 'delete',
      'owner' => FALSE,
    ],
  ];

  // Add default permissions.
  foreach ($operations as $values) {
    $permission = new GroupContentOperationPermission($values);
    $permission
      ->setEntityType($group_content_entity_type_id)
      ->setBundle($group_content_bundle_id)
      ->setDefaultRoles([
      OgRoleInterface::ADMINISTRATOR,
    ]);
    $permissions[] = $permission;
  }
  return $permissions;
}