public function OgEventSubscriber::provideDefaultNodePermissions in Organic groups 8
Provides default permissions for the Node entity.
Parameters
\Drupal\og\Event\PermissionEventInterface $event: The OG permission event.
File
- src/
EventSubscriber/ OgEventSubscriber.php, line 176
Class
- OgEventSubscriber
- Event subscribers for Organic Groups.
Namespace
Drupal\og\EventSubscriberCode
public function provideDefaultNodePermissions(PermissionEventInterface $event) {
$bundle_ids = $event
->getGroupContentBundleIds();
if (!array_key_exists('node', $bundle_ids)) {
return;
}
$permissions = [];
$bundle_info = $this->entityTypeBundleInfo
->getBundleInfo('node');
foreach ($bundle_ids['node'] as $bundle_id) {
$args = [
'%type_name' => $bundle_info[$bundle_id]['label'],
];
$permission_values = [
[
'name' => "create {$bundle_id} content",
'title' => $this
->t('%type_name: Create new content', $args),
'operation' => 'create',
],
[
'name' => "edit own {$bundle_id} content",
'title' => $this
->t('%type_name: Edit own content', $args),
'operation' => 'update',
'owner' => TRUE,
],
[
'name' => "edit any {$bundle_id} content",
'title' => $this
->t('%type_name: Edit any content', $args),
'operation' => 'update',
'owner' => FALSE,
],
[
'name' => "delete own {$bundle_id} content",
'title' => $this
->t('%type_name: Delete own content', $args),
'operation' => 'delete',
'owner' => TRUE,
],
[
'name' => "delete any {$bundle_id} content",
'title' => $this
->t('%type_name: Delete any content', $args),
'operation' => 'delete',
'owner' => FALSE,
],
];
foreach ($permission_values as $values) {
$values += [
'entity type' => 'node',
'bundle' => $bundle_id,
];
$permissions[] = new GroupContentOperationPermission($values);
}
}
$event
->setPermissions($permissions);
}